Sha256: 152e5880a34aaa889c3cc597dce8e1653a4c7d6d8820ab97a7fe8632dfccffdc

Contents?: true

Size: 959 Bytes

Versions: 6

Compression:

Stored size: 959 Bytes

Contents

require 'spec_helper'

describe HTTP::AuthorizationHeader::BearerToken do
  describe '.new' do
    it 'fails when options is not a Hash' do
      expect { described_class.new '[TOKEN]' }.to raise_error
    end

    it 'fails when :token is not given' do
      expect { described_class.new :encode => true }.to raise_error
    end
  end

  describe '#to_s' do
    let(:token)   { 'foobar' * 100 }
    let(:builder) { described_class.new options.merge :token => token }

    subject { builder.to_s }

    context 'when :encode => true' do
      let(:options) { {:encode => true} }
      it { should eq "Bearer #{Base64.strict_encode64 token}" }
      it { should match(/^Bearer [^\s]+$/) }
    end

    context 'when :encode => false' do
      let(:options) { {:encode => false} }
      it { should eq "Bearer #{token}" }
    end

    context 'when :encode not specified' do
      let(:options) { {} }
      it { should eq "Bearer #{token}" }
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
http-0.6.4 spec/http/authorization_header/bearer_token_spec.rb
http-0.6.3 spec/http/authorization_header/bearer_token_spec.rb
http-0.6.2 spec/http/authorization_header/bearer_token_spec.rb
http-0.6.1 spec/http/authorization_header/bearer_token_spec.rb
http-0.6.0 spec/http/authorization_header/bearer_token_spec.rb
http-0.6.0.pre spec/http/authorization_header/bearer_token_spec.rb