Sha256: f9a748f0df2a6073a8f716d0a36ef3e14ea4a429eddfdd01302779c15b3a3ce4

Contents?: true

Size: 1.85 KB

Versions: 1

Compression:

Stored size: 1.85 KB

Contents

require "spec_helper"

describe Redbooth::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) { Redbooth::Request::Base.new(info) }
  let(:connection) { double(:connection) }
  let(:validator) { double(:validator) }

  before :each do
    allow(Redbooth::Request::Connection).to receive(:new).and_return(connection)
    allow(Redbooth::Request::Validator).to receive(:new).and_return(validator)
    Redbooth.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{ Redbooth::AuthenticationError }
    end
    it "performs an https request" do
      allow_any_instance_of(Redbooth::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)

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

  describe "#valid?" do
    it 'is not valid if no info object given' do
      expect(Redbooth::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

1 entries across 1 versions & 1 rubygems

Version Path
redbooth-ruby-0.0.2 spec/redbooth/request/base_spec.rb