|
2 | 2 |
|
3 | 3 | require 'spec_helper' |
4 | 4 |
|
5 | | -describe Github::ParamsHash do |
| 5 | +RSpec.describe Github::ParamsHash do |
6 | 6 | let(:object) { described_class } |
7 | 7 |
|
8 | | - subject { object.new(hash) } |
| 8 | + subject(:params) { object.new(hash) } |
9 | 9 |
|
10 | | - context 'converts key to string' do |
11 | | - let(:hash) { {:foo => 123 }} |
| 10 | + context 'when empty' do |
| 11 | + let(:hash) { {} } |
| 12 | + |
| 13 | + it { expect(params.options).to eq({:raw => false}) } |
| 14 | + |
| 15 | + it { expect(params.data).to eq({}) } |
12 | 16 |
|
13 | | - it { expect(subject).to be_a(Github::ParamsHash)} |
| 17 | + it { expect(params.accept).to eq(nil) } |
| 18 | + end |
| 19 | + |
| 20 | + context 'converts key to string' do |
| 21 | + let(:hash) { {foo: 123 } } |
14 | 22 |
|
15 | | - it { expect(subject['foo']).to eql(123) } |
| 23 | + it { expect(params['foo']).to eql(123) } |
16 | 24 |
|
17 | | - it { expect(subject.data).to eql({"foo" => 123}) } |
| 25 | + it { expect(params.data).to eql({"foo" => 123}) } |
18 | 26 | end |
19 | 27 |
|
20 | 28 | context 'media' do |
21 | | - let(:hash) { {:media => "raw"} } |
| 29 | + let(:hash) { {media: "raw"} } |
22 | 30 |
|
23 | 31 | it 'parses media key' do |
24 | | - expect(subject.media).to eql('application/vnd.github.v3.raw+json') |
| 32 | + expect(params.media).to eql('application/vnd.github.v3.raw+json') |
25 | 33 | end |
26 | 34 | end |
27 | 35 |
|
28 | 36 | context 'with accept' do |
29 | | - let(:hash) { {:accept => "application/json"} } |
| 37 | + let(:hash) { {accept: "application/json"} } |
30 | 38 |
|
31 | 39 | it 'overwrites media key' do |
32 | | - expect(subject.accept).to eql('application/json') |
| 40 | + expect(params.accept).to eql('application/json') |
| 41 | + expect(params.to_hash).to eq({'accept' => 'application/json'}) |
33 | 42 | end |
34 | 43 | end |
35 | 44 |
|
36 | 45 | context 'without accept' do |
37 | 46 | let(:hash) { {} } |
38 | 47 |
|
39 | 48 | it 'overwrites media key' do |
40 | | - expect(subject.accept).to be_nil |
| 49 | + expect(params.accept).to be_nil |
41 | 50 | end |
42 | 51 | end |
43 | 52 |
|
44 | | - context 'extract data' do |
45 | | - let(:hash) { {:data => 'foobar'} } |
| 53 | + context 'when data' do |
| 54 | + let(:hash) { {data: 'foobar'} } |
46 | 55 |
|
47 | | - it { expect(subject.data).to eql('foobar') } |
| 56 | + it 'extracts data key' do |
| 57 | + expect(params.data).to eql('foobar') |
| 58 | + expect(params.to_hash).to eql({'data' => 'foobar'}) |
| 59 | + end |
| 60 | + end |
| 61 | + |
| 62 | + context 'when content_type' do |
| 63 | + let(:hash) { {content_type: 'application/octet-stream'} } |
| 64 | + |
| 65 | + it 'extracts content_type key' do |
| 66 | + expect(params.options[:headers]).to eql(hash) |
| 67 | + end |
48 | 68 | end |
49 | 69 |
|
50 | | - context 'extracts options headers' do |
51 | | - let(:hash) { {:content_type => 'application/octet-stream'} } |
| 70 | + context 'when header' do |
| 71 | + let(:hash) { {headers: {"X-GitHub-OTP" => "<2FA token>"}} } |
52 | 72 |
|
53 | | - it { expect(subject.options[:headers]).to eql(hash) } |
| 73 | + it "sets headers" do |
| 74 | + expect(params.options[:headers]).to eql({"X-GitHub-OTP" => "<2FA token>" }) |
| 75 | + end |
54 | 76 | end |
55 | 77 |
|
56 | 78 | context 'merges defaults' do |
57 | 79 | let(:hash) { { :homepage => "https://tty.github.io" }} |
58 | 80 | let(:defaults) { |
59 | | - { "homepage" => "https://github.com", |
60 | | - "private" => false} |
| 81 | + { "homepage" => "https://github.com", |
| 82 | + "private" => false} |
61 | 83 | } |
62 | 84 |
|
63 | 85 | it 'correctly updates values' do |
64 | 86 | subject.merge_default(defaults) |
65 | | - expect(subject['homepage']).to eql("https://tty.github.io") |
66 | | - expect(subject['private']).to be_false |
| 87 | + expect(params['homepage']).to eql("https://tty.github.io") |
| 88 | + expect(params['private']).to be_false |
67 | 89 | end |
68 | 90 | end |
69 | 91 |
|
70 | 92 | context 'strict encode' do |
71 | | - let(:hash) { { :content => "puts 'hello ruby'"} } |
| 93 | + let(:hash) { {content: "puts 'hello ruby'"} } |
72 | 94 |
|
73 | | - it { expect(subject.strict_encode64('content')).to eql('cHV0cyAnaGVsbG8gcnVieSc=') } |
| 95 | + it { expect(params.strict_encode64('content')).to eql('cHV0cyAnaGVsbG8gcnVieSc=') } |
74 | 96 | end |
75 | 97 | end |
0 commit comments