forked from piotrmurach/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcallbacks_spec.rb
More file actions
59 lines (48 loc) · 1.11 KB
/
callbacks_spec.rb
File metadata and controls
59 lines (48 loc) · 1.11 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
# encoding: utf-8
require 'spec_helper'
class ApiTest < Github::API
before_request :authorize, only: ['list']
after_request :stats
def list(a, b)
(@called ||= []) << "list_#{a}_#{b}"
end
def get(a, b)
(@called ||= []) << "get_#{a}_#{b}"
end
private
def authorize
(@called ||= []) << 'authorize'
end
def stats
(@called ||= []) << 'stats'
end
end
describe Github::API, '#callbacks' do
it "retrieves only public api methods" do
expect(ApiTest.request_methods.to_a - [
'list',
'list_with_callback_apitest',
'list_without_callback_apitest',
'get',
'get_with_callback_apitest',
'get_without_callback_apitest'
]).to be_empty
end
it "execute before callback" do
api_test = ApiTest.new
api_test.list(:foo, :bar)
expect(api_test.instance_variable_get("@called")).to eq([
'authorize',
'list_foo_bar',
'stats'
])
end
it "skips request" do
api_test = ApiTest.new
api_test.get(:foo, :bar)
expect(api_test.instance_variable_get("@called")).to eq([
'get_foo_bar',
'stats'
])
end
end