Sha256: 4715928300e5d5a01cfb787d2f3bfcf3884bec043a0ca24c1596f34b7ad1d535

Contents?: true

Size: 1.89 KB

Versions: 8

Compression:

Stored size: 1.89 KB

Contents

require 'spec_helper'

describe RedboothRuby::Request::Base do
  let(:consumer_key) { '_your_consumen_key_' }
  let(:consumer_secret) { '_your_consumen_secret_' }
  let(:info) { double(:info, session: session ) }
  let(:session) { double(:session, valid?: true ) }
  let(:request_base) { RedboothRuby::Request::Base.new(info) }
  let(:connection) { double(:connection) }
  let(:validator) { double(:validator) }

  before :each do
    allow(RedboothRuby::Request::Connection).to receive(:new).and_return(connection)
    allow(RedboothRuby::Request::Validator).to receive(:new).and_return(validator)
    RedboothRuby.config do |configuration|
      configuration[:consumer_key] = consumer_key
      configuration[:consumer_secret] = consumer_secret
    end
  end

  describe '#perform' do
    it 'raises AuthenticationError if request is not valid' do
      allow(request_base).to receive(:valid?).and_return(false)
      expect{request_base.perform}.to raise_error{ RedboothRuby::AuthenticationError }
    end
    it 'performs an https request' do
      allow_any_instance_of(RedboothRuby::Request::Base).to receive(:valid?).and_return(true)

      expect(connection).to receive(:set_request_data)
      expect(connection).to receive(:request)
      expect(validator).to receive(:validated_response_for)

      RedboothRuby::Request::Base.new(nil).perform
    end
  end

  describe '#valid?' do
    it 'is not valid if no info object given' do
      expect(RedboothRuby::Request::Base.new(nil)).to_not be_valid
    end
    it 'is not valid if there is no session in info object' do
      allow(info).to receive(:session).and_return(nil)
      expect(request_base).to_not be_valid
    end
    it 'is not valid if session is invalid' do
      allow(session).to receive(:valid?).and_return(false)
      expect(request_base).to_not be_valid
    end
    it 'id valid othercase' do
      expect(request_base).to be_valid
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
redbooth-ruby-0.2.3 spec/redbooth-ruby/request/base_spec.rb
redbooth-ruby-0.2.2 spec/redbooth-ruby/request/base_spec.rb
redbooth-ruby-0.2.1 spec/redbooth-ruby/request/base_spec.rb
redbooth-ruby-0.2.0 spec/redbooth-ruby/request/base_spec.rb
redbooth-ruby-0.1.4 spec/redbooth-ruby/request/base_spec.rb
redbooth-ruby-0.1.3 spec/redbooth-ruby/request/base_spec.rb
redbooth-ruby-0.1.1 spec/redbooth-ruby/request/base_spec.rb
redbooth-ruby-0.1.0 spec/redbooth-ruby/request/base_spec.rb