require "spec_helper" describe 'ApiClient' do let(:subject) { AgridClient::ApiClient.new } describe "#new" do context "without arguments" do it "initialize with default configuration" do version = AgridClient::VERSION expect(subject.default_headers).to eq({ 'Content-Type' => 'application/json', 'User-Agent' => "agrid_client/#{version}/ruby" }) end end context "with configuration argument" do let(:configuration) { AgridClient::Configuration.new { |c| c.host = 'http://test.com' } } let(:subject) { AgridClient::ApiClient.new(configuration) } it "initialize with configuration received" do expect(subject.config.host).to eq('test.com') end end end describe "#call_api" do it 'make a call to API' do VCR.use_cassette('services') do response = subject.call_api('GET','services') expect(response).to be_an(Array) end end context "with options" do it "make a call to API with options" do subject.call_api('GET','services', header_params: {'A-HEADER': 'olar'}, query_params: {key: 'value'}) expect(a_get('services').with( headers: {'A-HEADER': 'olar'}, query: {key: 'value'})).to have_been_made end end context "with return type" do context "valid primitive type" do before(:each) do stub_get('services').to_return(body: '[1,2,3]', headers: {'Content-Type': 'application/json'}) end it "return deserialized response" do expect(subject.call_api('GET', 'services', {return_type: 'Array'})[0]).to eq([1,2,3]) end end end end end