Sha256: 847b344cfc90501a2cf7e8c7c2191e46be8e89d1e24baee4a28168ab48a20427
Contents?: true
Size: 1.73 KB
Versions: 2
Compression:
Stored size: 1.73 KB
Contents
require "spec_helper" describe TriviaCrack::API::Question do let(:session) { TriviaCrack::Session.new session_id: "session", user_id: 1 } let(:client) { (Class.new(APIStub) { include TriviaCrack::API::Question }).new session } let(:response) { double(code: code, body: raw_data) } before { allow(Unirest).to receive(:post) { response } } describe "#answer_question" do subject { client.answer_question game_id, question, answer } let(:raw_data) { SpecData.get "answer.json" } let(:question) { double(id: 1, correct_answer: 1, type: "NORMAL", category: "SPORTS") } let(:game_id) { 22 } context 'given that the question was answer correctly' do let(:code) { 200 } let(:answer) { 1 } it { expect(TriviaCrack::Parsers::GameParser).to receive(:parse).once; subject } it { expect(subject[0]).to be_a TriviaCrack::Game } it { expect(subject[1]).to be true } end context 'given that the question was answer incorrectly' do let(:code) { 200 } let(:answer) { 0 } it { expect(TriviaCrack::Parsers::GameParser).to receive(:parse).once; subject } it { expect(subject[0]).to be_a TriviaCrack::Game } it { expect(subject[1]).to be false } end context 'given that the request fails' do let(:code) { 400 } let(:answer) { 1 } 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}/games/#{game_id}/answers")) } end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
triviacrack-0.3.2 | spec/api/question_spec.rb |
triviacrack-0.3.0 | spec/api/question_spec.rb |