-
Notifications
You must be signed in to change notification settings - Fork 317
Expand file tree
/
Copy pathgithub_api_steps.rb
More file actions
111 lines (93 loc) · 2.85 KB
/
github_api_steps.rb
File metadata and controls
111 lines (93 loc) · 2.85 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
Given /^I have github instance$/ do
@github = Github.new(
:basic_auth => SETTINGS['basic_auth'],
:oauth_token => SETTINGS['oauth_token']
)
end
Given /^I have "([^"]*)" instance$/ do |api_classes|
@instance = convert_to_constant(api_classes).new(
:basic_auth => SETTINGS['basic_auth'],
:oauth_token => SETTINGS['oauth_token']
)
end
Given /^I do not verify ssl$/ do
@instance.ssl = {:verify => false}
end
Given /^I set the following (?:attribute|attributes) of instance:$/ do |table|
table.hashes.each do |element|
element.each do |attr, val|
@instance.send(:"#{attr}=", val)
end
end
end
When /^I am not authorized$/ do
[:basic_auth, :login, :password, :oauth_token].each do |attr|
@instance.send("#{attr}=", nil)
end
end
When /^I fetch "([^"]*)"$/ do |method|
@response = @github.send(method.to_sym)
end
When /^I call (.*)$/ do |api_part|
@response = @instance.send(api_part.to_sym)
end
When /^I will have access to "([^"]*)" API$/ do |api|
expect(@response.class.to_s).to match api
end
When /^I want(?: to|) (.*) (?:resource|resources)$/ do |method|
@method = method
end
When /^I want(?: to|) (.*) (?:resource|resources) with the following (?:params|arguments):$/ do |method, table|
table.hashes.each do |attributes|
@method = method.to_sym
@attributes = attributes
end
end
When /^I pass the following request options:$/ do |table|
table.hashes.each do |options|
options.each do |k, v|
begin
options[k] = Integer(v) # Github API requires Integers in data to be sent as literal integers
rescue ArgumentError
next
end
end
@options = options
end
end
When /^I am looking for "([^"]*)" with the following params:$/ do |method, table|
table.hashes.each do |attributes|
@method = method.to_sym
@attributes = attributes
end
end
When /^I make request$/ do
@options ||= {}
@attributes ||= {}
@response = @instance.send @method, *@attributes.values, @options
end
When /^I request (.*) page$/ do |link|
@next_response = @response.send :"#{link}_page"
end
When /^I iterate through collection pages$/ do
@pages = []
@response.each_page do |page|
@pages << page.flatten
end
end
Then /^the request header (.*) should be$/ do |header, value|
expect(@response.headers.env[:request_headers][header]).to eql(value)
end
Then /^the response collection of resources is different for "([^"]*)" attribute$/ do |attr|
expect(@next_response.first.send(:"#{attr}")).to_not eql @response.first.send(:"#{attr}")
end
Then /^this collection should include first page$/ do
expect(@pages.flatten.map(&:name)).to include @response.first.name
end
Then /^request should fail with "([^"]*)"$/ do |exception|
@options ||= {}
@attributes ||= {}
expect {
@response = @instance.send @method, *@attributes.values, @options
}.to raise_error(convert_to_constant(exception))
end