spec/board/client_spec.rb in board-client-0.3.0 vs spec/board/client_spec.rb in board-client-0.99.0

- old
+ new

@@ -1,33 +1,11 @@ require 'spec_helper' -module RequestTracking - - class Request < Struct.new(:path, :params, :method); end - - def request(path, params, method) - requests << Request.new(path, params, method) - end - - def requests - @requests ||= [] - end - -end - describe Board::Client do - let(:client) { - client = Board::Client.new('VALID_KEY') - client.extend(RequestTracking) - client - } + let(:client) { Board::Client.new('VALID_KEY') } - def last_request - @last_request ||= client.requests.last - end - describe "when creating" do context 'and missing an API key' do it 'should raise an error' do expect { Board::Client.new }.to raise_error end @@ -38,69 +16,35 @@ Board::Client.new('API_KEY') end end end - describe '#candidate_searches' do - it 'performs the correct request' do - client.candidate_searches(:keywords => 'ruby', :location => 'Cincinnati') + describe "when processing responses" do + { + 400 => Board::Client::BadRequest, + 401 => Board::Client::Unauthorized, + 403 => Board::Client::Forbidden, + 404 => Board::Client::NotFound, + 406 => Board::Client::NotAcceptable, + 409 => Board::Client::Conflict, + 422 => Board::Client::UnprocessableEntity, + 500 => Board::Client::InternalServerError, + 501 => Board::Client::NotImplemented, + 502 => Board::Client::BadGateway, + 503 => Board::Client::ServiceUnavailable, + }.each do |code, exception| + context "when HTTP status code is #{code}" do + before do + stub_request(:get, 'http://localhost:3000/api/v1/users/42'). + to_return(:status => code) + end - last_request.path.should == '/candidate_searches' - last_request.method.should == :get - last_request.params.should == { - :keywords => "ruby", - :location => "Cincinnati", - } - end - end - - describe '#find_user' do - it 'performs the correct request' do - client.find_user(:email => 'bob@rm.com') - - last_request.path.should == '/users' - last_request.method.should == :get - last_request.params.should == { :email => 'bob@rm.com' } - end - end - - describe '#mark_user_invalid' do - it 'performs the correct request' do - client.mark_user_invalid(:email => 'bob@rm.com') - - last_request.path.should == '/users/invalid' - last_request.method.should == :get - last_request.params.should == { :email => 'bob@rm.com' } - end - end - - describe '#unsubscribe' do - it 'performs the correct request' do - client.unsubscribe(:email => 'bob@rm.com') - - last_request.path.should == '/users/unsubscribe' - last_request.method.should == :get - last_request.params.should == { :email => 'bob@rm.com' } - end - end - - describe '#create_candidate_invitation' do - it 'performs the correct request' do - client.create_candidate_invitation(:email => 'bob@rm.com') - - last_request.path.should == '/candidate_invitations' - last_request.method.should == :post - last_request.params.should == { :email => 'bob@rm.com' } - end - end - - describe '#candidates' do - it 'performs the correct request' do - client.find_candidate(42) - - last_request.path.should == '/candidates/42' - last_request.method.should == :get - last_request.params.should == {} + it "raises #{exception.name} error" do + expect { + client.users.find(42) + }.to raise_error(exception) + end + end end end end