spec/kookaburra/api_client_spec.rb in kookaburra-2.0.0 vs spec/kookaburra/api_client_spec.rb in kookaburra-3.0.0

- old
+ new

@@ -1,5 +1,6 @@ +require 'spec_helper' require 'kookaburra/api_client' describe Kookaburra::APIClient do def url_for(uri) URI.join('http://example.com', uri).to_s @@ -14,20 +15,20 @@ let(:client) { double('RestClient') } shared_examples_for 'any type of HTTP request' do |http_verb| context "(#{http_verb})" do before(:each) do - client.stub(http_verb => response) + allow(client).to receive(http_verb).and_return(response) end it 'returns the response body' do expect(api.send(http_verb, '/foo')).to eq 'foo' end it 'raises an UnexpectedResponse if the request is not successful' do - response.stub(code: 500) - client.stub(http_verb).and_raise(RestClient::Exception.new(response)) + allow(response).to receive(:code) { 500 } + allow(client).to receive(http_verb).and_raise(RestClient::Exception.new(response)) expect{ api.send(http_verb, '/foo') } \ .to raise_error(Kookaburra::UnexpectedResponse) end let(:expect_client_to_receive_headers) { ->(expected_headers) { @@ -114,11 +115,11 @@ end shared_examples_for 'it encodes request data' do |http_verb| context "(#{http_verb})" do before(:each) do - client.stub(http_verb => response) + allow(client).to receive(http_verb) { response } end context 'when a custom encoder is specified' do let(:api) { klass = Class.new(Kookaburra::APIClient) do @@ -130,10 +131,10 @@ klass.new(configuration, client) } it "encodes input to requests" do expect(client).to receive(http_verb) do |_, data, _| - data.should == :some_encoded_data + expect(data).to eq :some_encoded_data response end api.send(http_verb, '/foo', :some_ruby_data) end