Sha256: 044b4438f54591ece049d95a6e0f34a19d24500c246e3d61c3694540b97155a4
Contents?: true
Size: 1.88 KB
Versions: 3
Compression:
Stored size: 1.88 KB
Contents
require "spec_helper" describe TriviaCrack::API::User do let(:session) { TriviaCrack::Session.new session_id: "session", user_id: 1 } let(:client) { (Class.new(APIStub) { include TriviaCrack::API::User }).new session } 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 username } let(:raw_data) { SpecData.get "search.json" } context 'given that the request is successful' do let(:code) { 200 } it { is_expected.to be 112 } end 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 subject { client.get_user } let(:raw_data) { SpecData.get "dashboard.json" } context 'given that the request is successful' do let(:code) { 200 } it { expect(TriviaCrack::Parsers::UserParser).to receive(:parse).once; subject } it { is_expected.to be_a TriviaCrack::User } end 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
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
triviacrack-0.4.0 | spec/api/user_spec.rb |
triviacrack-0.3.2 | spec/api/user_spec.rb |
triviacrack-0.3.0 | spec/api/user_spec.rb |