File: authorization_header_spec.rb

package info (click to toggle)
ruby-http 0.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 404 kB
  • ctags: 213
  • sloc: ruby: 2,397; makefile: 7
file content (41 lines) | stat: -rw-r--r-- 1,139 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require 'spec_helper'

describe HTTP::AuthorizationHeader do
  describe '.build' do
    context 'with unkown type' do
      let(:type) { :foobar }
      let(:opts) { {:foo => :bar} }

      it 'fails' do
        expect { described_class.build type, opts }.to raise_error
      end
    end

    context 'with :basic type' do
      let(:type) { :basic }
      let(:opts) { {:user => 'user', :pass => 'pass'} }

      it 'passes options to BasicAuth' do
        expect(described_class::BasicAuth).to receive(:new).with(opts)
        described_class.build type, opts
      end
    end

    context 'with :bearer type' do
      let(:type) { :bearer }
      let(:opts) { {:token => 'token', :encode => true} }

      it 'passes options to BearerToken' do
        expect(described_class::BearerToken).to receive(:new).with(opts)
        described_class.build type, opts
      end
    end
  end

  describe '.register' do
    it 'registers given klass in builders registry' do
      described_class.register :dummy, Class.new { def initialize(*); end }
      expect { described_class.build(:dummy, 'foobar') }.to_not raise_error
    end
  end
end