From 2b16defd4fb13a057eededeb73c596a9039f2f9f Mon Sep 17 00:00:00 2001 From: "Tj (bougyman) Vanderpoel" Date: Sun, 4 Jan 2026 17:56:14 -0600 Subject: [PATCH] test: got 100% coverage (branch and line) --- test/kalshi/client_test.rb | 32 ++++++++++++++++++++++++++ test/kalshi/contract_test.rb | 18 +++++++++++++++ test/kalshi/market/series_list_test.rb | 8 ++++++- 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 test/kalshi/client_test.rb create mode 100644 test/kalshi/contract_test.rb diff --git a/test/kalshi/client_test.rb b/test/kalshi/client_test.rb new file mode 100644 index 0000000..759e2c2 --- /dev/null +++ b/test/kalshi/client_test.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +require_relative '../helper' + +describe Rubyists::Kalshi::Client do + let(:base_url) { Rubyists::Kalshi.config.base_url } + + describe '#get' do + it 'raises Error on API error' do + stub_request(:get, "#{base_url}/error") + .to_return(status: 400, body: 'Bad Request') + + client = Rubyists::Kalshi::Client.new + error = assert_raises(Rubyists::Kalshi::Error) do + client.get('error') + end + assert_match(/API Error: 400 - Bad Request/, error.message) + end + end +end + +describe Rubyists::Kalshi do + describe '.client' do + it 'returns a client instance' do + assert_instance_of Rubyists::Kalshi::Client, Rubyists::Kalshi.client + end + + it 'returns the same instance' do + assert_same Rubyists::Kalshi.client, Rubyists::Kalshi.client + end + end +end diff --git a/test/kalshi/contract_test.rb b/test/kalshi/contract_test.rb new file mode 100644 index 0000000..7721351 --- /dev/null +++ b/test/kalshi/contract_test.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require_relative '../helper' + +describe Rubyists::Kalshi::Contract do + # rubocop:disable Lint/ConstantDefinitionInBlock + class TestContract < Rubyists::Kalshi::Contract + property :existing_prop + propertize :new_prop + end + # rubocop:enable Lint/ConstantDefinitionInBlock + + it 'handles existing definitions' do + # This test just ensures the class definition above runs and exercises the code path + assert_includes TestContract::Properties.members, :existing_prop + assert_includes TestContract::Properties.members, :new_prop + end +end diff --git a/test/kalshi/market/series_list_test.rb b/test/kalshi/market/series_list_test.rb index fe179f4..8c02bae 100644 --- a/test/kalshi/market/series_list_test.rb +++ b/test/kalshi/market/series_list_test.rb @@ -27,12 +27,18 @@ assert_equal({ series: [] }, response) end - it 'raises ArgumentError for invalid filters' do + it 'raises ArgumentError for invalid keys' do assert_raises(ArgumentError) do series_list.list(invalid_param: 'value') end end + it 'raises ArgumentError for invalid values' do + assert_raises(ArgumentError) do + series_list.list(status: 123) + end + end + it 'allows calling list on the class' do stub_request(:get, "#{base_url}/series") .to_return(status: 200, body: '{"series": []}', headers: { 'Content-Type' => 'application/json' })