forked from piotrmurach/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_spec.rb
More file actions
71 lines (58 loc) · 2.16 KB
/
api_spec.rb
File metadata and controls
71 lines (58 loc) · 2.16 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
require 'spec_helper'
describe Github::API do
let(:api) { Github::API.new }
let(:repos) { Github::Repos }
it { described_class.included_modules.should include Github::Authorization }
it { described_class.included_modules.should include Github::MimeType }
it { described_class.included_modules.should include Github::Connection }
it { described_class.included_modules.should include Github::Request }
context 'actions' do
it { described_class.new.should respond_to :api_methods_in }
it 'dynamically adds actions inspection to classes inheriting from api' do
repos.should respond_to :actions
repos.new.should respond_to :actions
end
it 'ensures output contains api methods' do
methods = [ 'method_a', 'method_b']
repos.stub(:instance_methods).and_return methods
output = capture(:stdout) {
api.api_methods_in(repos)
}
output.should =~ /.*method_a.*/
output.should =~ /.*method_b.*/
end
end
context '_process_basic_auth' do
let(:github) { Github.new :basic_auth => 'login:password' }
after { reset_authentication_for github }
it 'should parse authentication params' do
github.login.should eq 'login'
github.password.should eq 'password'
end
end
context '_set_api_client' do
it 'should set instantiated api class as main api client' do
repos_instance = repos.new
Github.api_client.should eq repos_instance
end
end
context '_normalize_params_keys' do
before do
@params = { 'a' => { :b => { 'c' => 1 }, 'd' => [ 'a', { :e => 2 }] } }
end
it "should stringify all the keys inside nested hash" do
actual = api.send(:_normalize_params_keys, @params)
expected = { 'a' => { 'b'=> { 'c' => 1 }, 'd' => [ 'a', { 'e'=> 2 }] } }
actual.should be_eql expected
end
end
context '_filter_params_key' do
it "should remove non valid param keys" do
valid = ['a', 'b', 'e']
hash = {'a' => 1, 'b' => 3, 'c' => 2, 'd'=> 4, 'e' => 5 }
actual = api.send(:_filter_params_keys, valid, hash)
expected = {'a' => 1, 'b' => 3, 'e' => 5 }
actual.should be_eql expected
end
end
end # Github::API