Sha256: 61d992b90965720f6d5c091b95677ba51e4d9cc2d650b7477d59e7dcdb277b76
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(status: code, body: raw_data) } before { allow(Faraday).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.6.0 | spec/api/login_spec.rb |
triviacrack-0.5.1 | spec/api/login_spec.rb |
triviacrack-0.5.0 | spec/api/login_spec.rb |