spec/api/user_spec.rb in triviacrack-0.2.0 vs spec/api/user_spec.rb in triviacrack-0.3.0

- old
+ new

@@ -8,12 +8,13 @@ let(:response) { double(code: code, body: raw_data) } before { allow(Unirest).to receive(:get) { response } } describe "#get_user_id" do + let(:username) { "example.2" } - subject { client.get_user_id "example.2" } + subject { client.get_user_id username } let(:raw_data) { SpecData.get "search.json" } context 'given that the request is successful' do let(:code) { 200 } @@ -23,10 +24,14 @@ context 'given that the request fails' do let(:code) { 400 } it { expect{ subject }.to raise_error TriviaCrack::Errors::RequestError } + it { expect{ subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError) + .and having_attributes(code: code)) } + it { expect{ subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError) + .and having_attributes(url: "/api/search?username=#{username}")) } end end describe "#get_user" do @@ -43,8 +48,12 @@ context 'given that the request fails' do let(:code) { 400 } it { expect{ subject }.to raise_error TriviaCrack::Errors::RequestError } + it { expect{ subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError) + .and having_attributes(code: code)) } + it { expect{ subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError) + .and having_attributes(url: "/api/users/#{session.user_id}")) } end end end