spec/api/question_spec.rb in triviacrack-0.3.2 vs spec/api/question_spec.rb in triviacrack-0.4.0
- old
+ new
@@ -15,20 +15,20 @@
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
+ context 'given that the question was answered 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
+ context 'given that the question was answered 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 }
@@ -36,9 +36,51 @@
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
+
+ describe "#answer_questions" do
+
+ subject { client.answer_questions game_id, questions, answers }
+
+ let(:raw_data) { SpecData.get "answer.json" }
+ let(:question_one) { double(id: 1, correct_answer: 1, type: "DUEL", category: "SPORTS") }
+ let(:question_two) { double(id: 2, correct_answer: 2, type: "DUEL", category: "ART") }
+ let(:questions) { [question_one, question_two] }
+ let(:game_id) { 22 }
+
+ context 'given that the questions were answered correctly' do
+ let(:code) { 200 }
+ let(:answers) { {1 => 1, 2 => 2} }
+
+ it { expect(TriviaCrack::Parsers::GameParser).to receive(:parse).once; subject }
+ it { expect(subject[0]).to be_a TriviaCrack::Game }
+ it { expect(subject[1][1]).to be true }
+ it { expect(subject[1][2]).to be true }
+ end
+
+ context 'given that a question was answered incorrectly' do
+ let(:code) { 200 }
+ let(:answers) { {1 => 1, 2 => 3} }
+
+ it { expect(TriviaCrack::Parsers::GameParser).to receive(:parse).once; subject }
+ it { expect(subject[0]).to be_a TriviaCrack::Game }
+ it { expect(subject[1][1]).to be true }
+ it { expect(subject[1][2]).to be false }
+ end
+
+ context 'given that the request fails' do
+ let(:code) { 400 }
+ let(:answers) { {1 => 1, 2 => 2} }
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)