Sha256: a3489808a2435acdd0146e7d4c87b40d7229ed512f42a564c33e29fd59564587

Contents?: true

Size: 1.4 KB

Versions: 2

Compression:

Stored size: 1.4 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 }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
triviacrack-0.2.0 spec/api/question_spec.rb
triviacrack-0.1.0 spec/api/question_spec.rb