fb_graph-mock 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/fb_graph/mock.rb +2 -2
- data/spec/fb_graph/mock_spec.rb +208 -3
- data/spec/spec_helper.rb +4 -1
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/lib/fb_graph/mock.rb
CHANGED
@@ -90,7 +90,7 @@ module FbGraph
|
|
90
90
|
)
|
91
91
|
end
|
92
92
|
unless File.exist? _response_file_path_
|
93
|
-
response_file_required!
|
93
|
+
response_file_required! _response_file_path_
|
94
94
|
end
|
95
95
|
File.new _response_file_path_
|
96
96
|
end
|
@@ -98,7 +98,7 @@ module FbGraph
|
|
98
98
|
def response_file_required!(response_path)
|
99
99
|
warn [
|
100
100
|
'No response file found.',
|
101
|
-
'
|
101
|
+
'You can register a response mock by sending a pull request to fb_graph-mock gem.',
|
102
102
|
"(at #{File.join 'mock_json', response_path.split('mock_json').last})"
|
103
103
|
].join("\n")
|
104
104
|
end
|
data/spec/fb_graph/mock_spec.rb
CHANGED
@@ -2,14 +2,219 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe FbGraph::Mock do
|
4
4
|
describe '#mock_graph' do
|
5
|
-
|
5
|
+
context 'when block given' do
|
6
|
+
it 'should register WebMock stub' do
|
7
|
+
request_signature = WebMock::RequestSignature.new :get, File.join(FbGraph::ROOT_URL, 'matake')
|
8
|
+
mock_graph :get, 'matake', 'users/me_private'
|
9
|
+
WebMock::StubRegistry.instance.should be_registered_request request_signature
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'when registered request not called' do
|
13
|
+
it 'should raise WebMock::AssertionFailure.error_class' do
|
14
|
+
expect do
|
15
|
+
mock_graph :get, 'me', 'users/me_private' do
|
16
|
+
# nothing to do
|
17
|
+
end
|
18
|
+
end.to raise_error WebMock::AssertionFailure.error_class
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'otherwise' do
|
23
|
+
it 'should not raise error' do
|
24
|
+
expect do
|
25
|
+
mock_graph :get, 'matake', 'users/me_private' do
|
26
|
+
FbGraph::User.fetch :matake
|
27
|
+
end
|
28
|
+
end.not_to raise_error
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'when no block given' do
|
34
|
+
context 'when registered request not called' do
|
35
|
+
it do
|
36
|
+
expect do
|
37
|
+
mock_graph :get, 'me', 'users/me_private'
|
38
|
+
end.not_to raise_error
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'when registered response file specified' do
|
44
|
+
it do
|
45
|
+
expect do
|
46
|
+
mock_graph :get, 'me', 'users/me_private'
|
47
|
+
end.not_to raise_error
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'when custom response file specified' do
|
52
|
+
it do
|
53
|
+
absolute_path = File.join File.dirname(__FILE__), '../../mock_json/users/me_private.json'
|
54
|
+
expect do
|
55
|
+
mock_graph :get, 'me', absolute_path
|
56
|
+
end.not_to raise_error
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'when no response file found' do
|
61
|
+
it do
|
62
|
+
self.should_receive(:warn).with [
|
63
|
+
'No response file found.',
|
64
|
+
'You can register a response mock by sending a pull request to fb_graph-mock gem.',
|
65
|
+
'(at mock_json/not_registered.json)'
|
66
|
+
].join("\n")
|
67
|
+
expect do
|
68
|
+
mock_graph :get, 'me', 'not_registered'
|
69
|
+
end.to raise_error Errno::ENOENT, /No such file or directory/
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'when params given' do
|
74
|
+
let(:params) do
|
75
|
+
{:foo => 'bar'}
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'when GET' do
|
79
|
+
it do
|
80
|
+
request_signature = WebMock::RequestSignature.new :get, File.join(FbGraph::ROOT_URL, "matake?#{params.to_query}")
|
81
|
+
mock_graph :get, 'matake', 'users/me_private', :params => params
|
82
|
+
WebMock::StubRegistry.instance.should be_registered_request request_signature
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
context 'when POST' do
|
87
|
+
it do
|
88
|
+
request_signature = WebMock::RequestSignature.new :post, File.join(FbGraph::ROOT_URL, 'me/feed'), :body => params.to_query
|
89
|
+
mock_graph :post, 'me/feed', 'users/feed/post_without_access_token', :params => params
|
90
|
+
WebMock::StubRegistry.instance.should be_registered_request request_signature
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
context 'when access_token given' do
|
96
|
+
let(:params) do
|
97
|
+
{:access_token => access_token}
|
98
|
+
end
|
99
|
+
let(:access_token) do
|
100
|
+
'access_token'
|
101
|
+
end
|
102
|
+
|
103
|
+
context 'when GET' do
|
104
|
+
it do
|
105
|
+
request_signature = WebMock::RequestSignature.new :get, File.join(FbGraph::ROOT_URL, "matake?#{params.to_query}")
|
106
|
+
mock_graph :get, 'matake', 'users/me_private', :access_token => access_token
|
107
|
+
WebMock::StubRegistry.instance.should be_registered_request request_signature
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context 'when POST' do
|
112
|
+
it do
|
113
|
+
request_signature = WebMock::RequestSignature.new :post, File.join(FbGraph::ROOT_URL, 'me/feed'), :body => params.to_query
|
114
|
+
mock_graph :post, 'me/feed', 'users/feed/post_without_access_token', :access_token => access_token
|
115
|
+
WebMock::StubRegistry.instance.should be_registered_request request_signature
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context 'when status given' do
|
121
|
+
it 'should mock response with given status' do
|
122
|
+
expect do
|
123
|
+
mock_graph :get, 'me', 'users/me_public', :status => [401, 'Unauthorized'] do
|
124
|
+
FbGraph::User.fetch :me
|
125
|
+
end
|
126
|
+
end.to raise_error FbGraph::Unauthorized
|
127
|
+
end
|
128
|
+
end
|
6
129
|
end
|
7
130
|
|
8
131
|
describe '#mock_fql' do
|
9
|
-
|
132
|
+
let(:query) { 'SELECT * FROM users WHERE uid=me' }
|
133
|
+
|
134
|
+
context 'when block given' do
|
135
|
+
it 'should register WebMock stub' do
|
136
|
+
request_signature = WebMock::RequestSignature.new :get, File.join(FbGraph::ROOT_URL, "fql?q=#{URI.encode query}")
|
137
|
+
mock_fql query, 'query/user/with_valid_token'
|
138
|
+
WebMock::StubRegistry.instance.should be_registered_request request_signature
|
139
|
+
end
|
140
|
+
|
141
|
+
context 'when registered request not called' do
|
142
|
+
it 'should raise WebMock::AssertionFailure.error_class' do
|
143
|
+
expect do
|
144
|
+
mock_fql query, 'query/user/with_valid_token' do
|
145
|
+
# nothing to do
|
146
|
+
end
|
147
|
+
end.to raise_error WebMock::AssertionFailure.error_class
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
context 'otherwise' do
|
152
|
+
it 'should not raise error' do
|
153
|
+
expect do
|
154
|
+
mock_fql query, 'query/user/with_valid_token' do
|
155
|
+
FbGraph::Query.fetch query
|
156
|
+
end
|
157
|
+
end.not_to raise_error
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
context 'when no block given' do
|
163
|
+
context 'when registered request not called' do
|
164
|
+
it do
|
165
|
+
expect do
|
166
|
+
mock_fql query, 'query/user/with_valid_token'
|
167
|
+
end.not_to raise_error
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
context 'when registered response file specified' do
|
173
|
+
it do
|
174
|
+
expect do
|
175
|
+
mock_fql query, 'query/user/with_valid_token'
|
176
|
+
end.not_to raise_error
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
context 'when custom response file specified' do
|
181
|
+
it do
|
182
|
+
absolute_path = File.join File.dirname(__FILE__), '../../mock_json/query/user/with_valid_token.json'
|
183
|
+
expect do
|
184
|
+
mock_fql query, absolute_path
|
185
|
+
end.not_to raise_error
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
context 'when no response file found' do
|
190
|
+
it do
|
191
|
+
self.should_receive(:warn).with [
|
192
|
+
'No response file found.',
|
193
|
+
'You can register a response mock by sending a pull request to fb_graph-mock gem.',
|
194
|
+
'(at mock_json/not_registered.json)'
|
195
|
+
].join("\n")
|
196
|
+
expect do
|
197
|
+
mock_fql query, 'not_registered'
|
198
|
+
end.to raise_error Errno::ENOENT, /No such file or directory/
|
199
|
+
end
|
200
|
+
end
|
10
201
|
end
|
11
202
|
|
12
203
|
describe '#request_to' do
|
13
|
-
it
|
204
|
+
it 'should assert whether WebMock::NetConnectNotAllowedError' do
|
205
|
+
request_signature = WebMock::RequestSignature.new :get, File.join(FbGraph::ROOT_URL, 'me')
|
206
|
+
expect do
|
207
|
+
error = WebMock::NetConnectNotAllowedError.new request_signature
|
208
|
+
raise error
|
209
|
+
end.to request_to '/me'
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
describe '#registered_mocks' do
|
214
|
+
it do
|
215
|
+
registered = FbGraph::Mock.registered_mocks
|
216
|
+
registered.should be_instance_of Array
|
217
|
+
registered.should_not be_blank
|
218
|
+
end
|
14
219
|
end
|
15
220
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fb_graph-mock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fb_graph
|