forked from piotrmurach/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_spec.rb
More file actions
88 lines (66 loc) · 2.37 KB
/
Copy pathparse_spec.rb
File metadata and controls
88 lines (66 loc) · 2.37 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# encoding: utf-8
require 'spec_helper'
describe Github::API::Arguments, '#parse' do
let(:object) { described_class }
let(:api) { Github::Client::Repos.new }
subject(:arguments) { object.new(api: api, required: required).parse(*args) }
after { api.user =nil; api.repo = nil }
context 'with required' do
let(:required) { [:user, :repo] }
let(:args) { ['peter-murach', 'github', {page: 23}] }
it "parses the request options" do
expect(arguments.params).to eq({"page" => 23})
end
it "allows to retrieve user" do
expect(arguments['user']).to eq('peter-murach')
expect(arguments[:user]).to eq('peter-murach')
expect(arguments.user).to eq('peter-murach')
end
it "allows to retrieve repo" do
expect(arguments['repo']).to eq('github')
expect(arguments[:repo]).to eq('github')
expect(arguments.repo).to eq('github')
end
it "reports about unknown property" do
expect(arguments['unknown']).to be_nil
expect { arguments.unknown}.to raise_error(NoMethodError)
end
context 'when no arguments searches attributes hash' do
let(:args) { nil }
it 'asserts lack of presence of hash parameters' do
expect { subject }.to raise_error(ArgumentError)
end
end
context 'with nil argument' do
let(:args) { [nil, 'github', {page: 23}] }
it 'raises an error' do
expect { subject }.to raise_error(ArgumentError, /parameter/)
end
end
context 'when arguments are inside hash' do
let(:args) { [{user: 'peter-murach', repo: 'github', page: 23}] }
it 'allows to retrieve required parameter' do
expect(arguments['user']).to eq('peter-murach')
expect(arguments[:user]).to eq('peter-murach')
expect(arguments.user).to eq('peter-murach')
end
it "doesn't polute global namespace" do
expect(arguments.api.user).to_not eq('peter-murach')
end
end
end
context 'with insufficient required' do
let(:required) { [:user, :repo] }
let(:args) { ['peter-murach', {page: 23}] }
it 'raises an error' do
expect { arguments }.to raise_error(ArgumentError, /Wrong number/)
end
end
context 'without required' do
let(:required) { [] }
let(:args) { [{page: 23}] }
it "parses request options" do
expect(arguments.params).to eq({"page" => 23})
end
end
end