Sha256: c7be68383f5fac2fb90ed086de46a94c4616b5cd115215c6493be484d826c835

Contents?: true

Size: 1.22 KB

Versions: 3

Compression:

Stored size: 1.22 KB

Contents

require "spec_helper"

describe TriviaCrack::API::Login do

  let(:client) { (Class.new(APIStub) { include TriviaCrack::API::Login }).new }

  let(:response) { double(code: code, body: raw_data) }

  before { allow(Unirest).to receive(:post) { response } }

  describe "#login" do

    subject { client.login email, password }

    let(:email) { "user@example.com" }
    let(:password) { "password123" }
    let(:raw_data) { SpecData.get "login.json" }

    context 'given that the request is successful' do
      let(:code) { 200 }

      it { expect(TriviaCrack::Parsers::SessionParser).to receive(:parse).once; subject }
      its(:user_id) { is_expected.to be 111 }
      its(:username) { is_expected.to eq "example" }
      its(:session_id) { is_expected.to eq "session123" }
    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/login')) }
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
triviacrack-0.4.0 spec/api/login_spec.rb
triviacrack-0.3.2 spec/api/login_spec.rb
triviacrack-0.3.0 spec/api/login_spec.rb