flickrmocks 0.8.14 → 0.8.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
1
 
2
2
  module FlickrMocks
3
- VERSION = File.read(File.expand_path("../../../VERSION", __FILE__)).strip
3
+ VERSION = '0.8.15'
4
4
  end
data/spec/api/api_spec.rb CHANGED
@@ -34,6 +34,7 @@ describe APP::Api do
34
34
  end
35
35
 
36
36
  context "class methods" do
37
+ let(:subject){klass}
37
38
  specify {klass.should respond_to(:photo)}
38
39
  context "photo" do
39
40
  it "returns expected Photo object" do
@@ -41,6 +42,10 @@ describe APP::Api do
41
42
  klass.photo({:photo =>photo.id,
42
43
  :secret => photo.secret}).should == APP::Photo.new(photo)
43
44
  end
45
+ context "arguments" do
46
+ let(:method){:photo}
47
+ it_behaves_like "object that expects single Hash argument"
48
+ end
44
49
  end
45
50
 
46
51
  specify {klass.should respond_to(:photos)}
@@ -48,18 +53,31 @@ describe APP::Api do
48
53
  it "returns expected PhotoSearch object" do
49
54
  flickr.photos.stub(:search).and_return(photos)
50
55
  klass.photos({:search_terms => 'iran'}).should ==
51
- APP::PhotoSearch.new(photos,{:search_terms => 'iran'})
56
+ APP::PhotoSearch.new(photos,{:search_terms => 'iran'})
57
+ end
58
+ it "raises error when non-hash argument provided" do
59
+ expect {
60
+ klass.photos([])
61
+ }.to raise_error(ArgumentError)
62
+ end
63
+ context "arguments" do
64
+ let(:method){:photos}
65
+ it_behaves_like "object that expects single Hash argument"
52
66
  end
53
67
  end
54
68
 
55
69
  specify {klass.should respond_to(:photo_sizes)}
56
- describe "photo_sizes" do
70
+ context "photo_sizes" do
57
71
  it "returns expected PhotoSizes object" do
58
72
  expected = APP::PhotoSizes.new(sizes)
59
73
  flickr.photos.stub(:getSizes).and_return(sizes)
60
74
  klass.photo_sizes(:photo => expected.id,
61
75
  :secret => expected.secret).should == expected
62
76
  end
77
+ context "arguments" do
78
+ let(:method){:photos}
79
+ it_behaves_like "object that expects single Hash argument"
80
+ end
63
81
  end
64
82
 
65
83
  specify {klass.should respond_to(:photo_details)}
@@ -70,6 +88,11 @@ describe APP::Api do
70
88
  klass.photo_details(:photo => photo.id,
71
89
  :secret => photo.secret).should == APP::PhotoDetails.new(photo,sizes)
72
90
  end
91
+ context "arguments" do
92
+ let(:method){:photo_details}
93
+ it_behaves_like "object that expects single Hash argument"
94
+ end
95
+
73
96
  end
74
97
 
75
98
  specify {klass.should respond_to(:interesting_photos)}
@@ -79,6 +102,10 @@ describe APP::Api do
79
102
  klass.interesting_photos({:date => '2010-01-01'}).should ==
80
103
  APP::PhotoSearch.new(interesting_photos,{:date => '2010-01-01'})
81
104
  end
105
+ context "arguments" do
106
+ let(:method){:interesting_photos}
107
+ it_behaves_like "object that expects single Hash argument"
108
+ end
82
109
  end
83
110
 
84
111
  specify {klass.should respond_to(:commons_institutions)}
@@ -88,6 +115,10 @@ describe APP::Api do
88
115
  klass.commons_institutions({}).should ==
89
116
  APP::CommonsInstitutions.new(commons_institutions)
90
117
  end
118
+ context "arguments" do
119
+ let(:method){:commons_institutions}
120
+ it_behaves_like "object that expects single Hash argument"
121
+ end
91
122
  end
92
123
 
93
124
  end
@@ -3,193 +3,314 @@ require 'spec_helper'
3
3
  describe APP::Stubs do
4
4
  let(:klass) {APP::Stubs}
5
5
  let(:fixtures) {APP::Fixtures.instance}
6
-
6
+ let(:flickr_stubs){klass::Flickr}
7
+ let(:api_stubs){klass::Api}
8
+ let(:api){APP::Api}
7
9
  context "class methods" do
8
-
9
- specify{klass.should respond_to(:stub_flickr)}
10
- context "stub_flickr" do
11
- before(:each) do
12
- klass.stub_flickr
13
- end
14
- it "stubs flickr.photos.search" do
15
- flickr.photos.search(:tags => 'france').should == fixtures.photos
16
- end
17
- it "stubs flickr.photos.getSizes" do
18
- flickr.photos.getSizes(:photo_id => '2121', :secret => '123abc').should == fixtures.photo_sizes
19
- end
20
- it "stubs flickr.photos.getInfo" do
21
- flickr.photos.getInfo(:photo_id => '2121', :secret => '123abc').should == fixtures.photo_details
22
- end
23
- it "stubs flickr.interestingness.getList" do
24
- flickr.interestingness.getList.should == fixtures.interesting_photos
25
- end
10
+ context "Flickr Stubs" do
26
11
 
27
- it "stubs flickr.commons.getInstitutions" do
28
- flickr.commons.getInstitutions.should == fixtures.commons_institutions
29
- end
30
-
31
- end
12
+ specify{flickr_stubs.should respond_to(:all)}
13
+ context "all" do
14
+ before(:each) do
15
+ flickr_stubs.all
16
+ end
17
+ it "stubs flickr.photos.search" do
18
+ flickr.photos.search(:tags => 'france').should == fixtures.photos
19
+ end
20
+ it "stubs flickr.photos.getSizes" do
21
+ flickr.photos.getSizes(:photo_id => '2121', :secret => '123abc').should == fixtures.photo_sizes
22
+ end
23
+ it "stubs flickr.photos.getInfo" do
24
+ flickr.photos.getInfo(:photo_id => '2121', :secret => '123abc').should == fixtures.photo_details
25
+ end
26
+ it "stubs flickr.interestingness.getList" do
27
+ flickr.interestingness.getList.should == fixtures.interesting_photos
28
+ end
32
29
 
33
- specify {klass.should respond_to(:stub_search)}
34
- context "stub_search: stubs for flickr.photos.search" do
35
- before(:each) do
36
- klass.stub_search
37
- end
38
- it "raises error when no options provided" do
39
- expect {
40
- flickr.photos.search
41
- }.to raise_error(
42
- FlickRaw::FailedResponse,
43
- /'flickr.photos.search' - Parameterless searches have been disabled. Please use flickr.photos.getRecent instead./
44
- )
45
- end
46
- it "raises when non-Hash option provided" do
47
- expect {
48
- flickr.photos.search([])
49
- }.to raise_error(
50
- FlickRaw::FailedResponse,
51
- /'flickr.photos.search' - Parameterless searches have been disabled. Please use flickr.photos.getRecent instead./
52
- )
53
- end
54
- it "raises error when neither :photo nor :user_id given" do
55
- expect {
56
- flickr.photos.search(:per_page => '3', :license => '4' )
57
- }.to raise_error(
58
- FlickRaw::FailedResponse,
59
- /'flickr.photos.search' - Parameterless searches have been disabled. Please use flickr.photos.getRecent instead./
60
- )
61
- end
62
- it "returns default photos fixture when :tags option given with non-garbage value" do
63
- flickr.photos.search(:tags => "france").should == fixtures.photos
64
- end
65
- it "returns empty photos when :tags option given with garbage value" do
66
- flickr.photos.search(:tags => "garbage").should == fixtures.empty_photos
67
- end
68
- it "returns author photo fixture when :user_id option given with non-garbage option" do
69
- flickr.photos.search(:user_id => '23@393').should == fixtures.author_photos
70
- end
71
- it "returns empty photos when :user_id is garbage" do
72
- flickr.photos.search(:user_id => 'garbage').should == fixtures.empty_photos
73
- end
74
- it "returns :author_photos when both :tags and :author_id provided with non-garbage option" do
75
- flickr.photos.search(:user_id => '23@23', :tags => '23@23').should == fixtures.author_photos
76
- end
77
- it "returns empty_photos when :tags is garbage and :author_id is non-garbage" do
78
- flickr.photos.search(:author_id => '23@393', :tags => 'garbage').should == fixtures.empty_photos
79
- end
80
- it "returns empty_photos when :author_id is garbage and :tags is non-garbage" do
81
- flickr.photos.search(:user_id=> 'garbage', :tags => 'france').should == fixtures.empty_photos
30
+ it "stubs flickr.commons.getInstitutions" do
31
+ flickr.commons.getInstitutions.should == fixtures.commons_institutions
32
+ end
33
+
82
34
  end
83
- it "returns :empty when both :author_id and :tags is garbage" do
84
- flickr.photos.search(:user_id=>'garbage',:tags => 'garbage').should == fixtures.empty_photos
35
+
36
+ specify {flickr_stubs.should respond_to(:search)}
37
+ context "stub_search: stubs for flickr.photos.search" do
38
+ before(:each) do
39
+ flickr_stubs.search
40
+ end
41
+ it "raises error when no options provided" do
42
+ expect {
43
+ flickr.photos.search
44
+ }.to raise_error(
45
+ FlickRaw::FailedResponse,
46
+ /'flickr.photos.search' - Parameterless searches have been disabled. Please use flickr.photos.getRecent instead./
47
+ )
48
+ end
49
+ it "raises when non-Hash option provided" do
50
+ expect {
51
+ flickr.photos.search([])
52
+ }.to raise_error(
53
+ FlickRaw::FailedResponse,
54
+ /'flickr.photos.search' - Parameterless searches have been disabled. Please use flickr.photos.getRecent instead./
55
+ )
56
+ end
57
+ it "raises error when neither :photo nor :user_id given" do
58
+ expect {
59
+ flickr.photos.search(:per_page => '3', :license => '4' )
60
+ }.to raise_error(
61
+ FlickRaw::FailedResponse,
62
+ /'flickr.photos.search' - Parameterless searches have been disabled. Please use flickr.photos.getRecent instead./
63
+ )
64
+ end
65
+ it "returns default photos fixture when :tags option given with non-garbage value" do
66
+ flickr.photos.search(:tags => "france").should == fixtures.photos
67
+ end
68
+ it "returns empty photos when :tags option given with garbage value" do
69
+ flickr.photos.search(:tags => "garbage").should == fixtures.empty_photos
70
+ end
71
+ it "returns author photo fixture when :user_id option given with non-garbage option" do
72
+ flickr.photos.search(:user_id => '23@393').should == fixtures.author_photos
73
+ end
74
+ it "returns empty photos when :user_id is garbage" do
75
+ flickr.photos.search(:user_id => 'garbage').should == fixtures.empty_photos
76
+ end
77
+ it "returns :author_photos when both :tags and :author_id provided with non-garbage option" do
78
+ flickr.photos.search(:user_id => '23@23', :tags => '23@23').should == fixtures.author_photos
79
+ end
80
+ it "returns empty_photos when :tags is garbage and :author_id is non-garbage" do
81
+ flickr.photos.search(:author_id => '23@393', :tags => 'garbage').should == fixtures.empty_photos
82
+ end
83
+ it "returns empty_photos when :author_id is garbage and :tags is non-garbage" do
84
+ flickr.photos.search(:user_id=> 'garbage', :tags => 'france').should == fixtures.empty_photos
85
+ end
86
+ it "returns :empty when both :author_id and :tags is garbage" do
87
+ flickr.photos.search(:user_id=>'garbage',:tags => 'garbage').should == fixtures.empty_photos
88
+ end
85
89
  end
86
- end
87
90
 
88
91
 
89
- specify {klass.should respond_to(:stub_getInfo)}
90
- context "stub_getInfo: which stubs flickr.photos.getInfo" do
91
- before(:each) do
92
- klass.stub_getInfo
93
- end
94
- it "raises error when no arguments provided" do
95
- expect { flickr.photos.getInfo.should }.to raise_error(
96
- FlickRaw::FailedResponse,
97
- /'flickr.photos.getInfo' - Photo not found/
98
- )
99
- end
100
- it "raises error when improper photo_id provided" do
101
- expect { flickr.photos.getInfo(:photo_id => 'garbage').should }.to raise_error(
102
- FlickRaw::FailedResponse,
103
- /'flickr.photos.getInfo' - Photo "garbage" not found \(invalid ID\)/
104
- )
105
- end
106
- it "raises error when non-hash option provided" do
107
- expect { flickr.photos.getInfo([]).should }.to raise_error(
108
- FlickRaw::FailedResponse,
109
- /'flickr.photos.getInfo' - Photo not found/
110
- )
111
- end
112
- it "raises photo details fixture when photo_id and secret given" do
113
- flickr.photos.getInfo(:secret => 'b5da82cd4e', :photo_id => '51028174').should == fixtures.photo_details
114
- end
115
- it "raises photo details fixture when photo_id and no secret given" do
116
- flickr.photos.getInfo(:photo_id => '51028174').should == fixtures.photo_details
117
- end
118
- end
92
+ specify {flickr_stubs.should respond_to(:getInfo)}
93
+ context "getInfo: which stubs flickr.photos.getInfo" do
94
+ before(:each) do
95
+ flickr_stubs.getInfo
96
+ end
97
+ it "returns photo details fixture when photo_id and secret given" do
98
+ flickr.photos.getInfo(:secret => 'b5da82cd4e', :photo_id => '51028174').should == fixtures.photo_details
99
+ end
100
+ it "returns photo details fixture when photo_id and no secret given" do
101
+ flickr.photos.getInfo(:photo_id => '51028174').should == fixtures.photo_details
102
+ end
119
103
 
120
- specify {klass.should respond_to(:stub_getSizes)}
121
- context "stub_getSizes: which stubs flickr.photos.getSizes" do
122
- before(:each) do
123
- klass.stub_getSizes
124
- end
125
- it "raises error when no options given" do
126
- expect {
127
- flickr.photos.getSizes
128
- }.to raise_error(
129
- FlickRaw::FailedResponse,
130
- /'flickr.photos.getSizes' - Photo not found/
131
- )
104
+ context "error conditions" do
105
+ it "raises error when no arguments provided" do
106
+ expect { flickr.photos.getInfo.should }.to raise_error(
107
+ FlickRaw::FailedResponse,
108
+ /'flickr.photos.getInfo' - Photo not found/
109
+ )
110
+ end
111
+ it "raises error when 'garbage' photo_id provided" do
112
+ expect { flickr.photos.getInfo(:photo_id => 'garbage') }.to raise_error(
113
+ FlickRaw::FailedResponse,
114
+ /'flickr.photos.getInfo' - Photo "garbage" not found \(invalid ID\)/
115
+ )
116
+ end
117
+ it "raises error when 'garbage' photo_id provided" do
118
+ expect {
119
+ flickr.photos.getInfo(:photo_id => nil)
120
+ }.to raise_error(FlickRaw::FailedResponse)
121
+ end
122
+
123
+ it "raises error when non-hash option provided" do
124
+ expect { flickr.photos.getInfo([]).should }.to raise_error(
125
+ FlickRaw::FailedResponse,
126
+ /'flickr.photos.getInfo' - Photo not found/
127
+ )
128
+ end
129
+ end
132
130
  end
133
- it "raises error when non-hash given" do
134
- expect {
135
- flickr.photos.getSizes []
136
- }.to raise_error(
137
- FlickRaw::FailedResponse,
138
- /'flickr.photos.getSizes' - Photo not found/
139
- )
131
+
132
+ specify {flickr_stubs.should respond_to(:getSizes)}
133
+ context "stub_getSizes: which stubs flickr.photos.getSizes" do
134
+ before(:each) do
135
+ flickr_stubs.getSizes
136
+ end
137
+ it "returns photo sizes fixture when option given" do
138
+ flickr.photos.getSizes(:secret => '3c4374b19e', :photo_id => "5102817422").should == fixtures.photo_sizes
139
+ end
140
+ context "error conditions" do
141
+ it "raises error when no options given" do
142
+ expect {
143
+ flickr.photos.getSizes
144
+ }.to raise_error(
145
+ FlickRaw::FailedResponse,
146
+ /'flickr.photos.getSizes' - Photo not found/
147
+ )
148
+ end
149
+ it "raises error when non-hash given" do
150
+ expect {
151
+ flickr.photos.getSizes []
152
+ }.to raise_error(
153
+ FlickRaw::FailedResponse,
154
+ /'flickr.photos.getSizes' - Photo not found/
155
+ )
156
+ end
157
+ it "raises error when photo_id is garbage" do
158
+ expect {
159
+ flickr.photos.getSizes :photo_id => 'garbage'
160
+ }.to raise_error(
161
+ FlickRaw::FailedResponse,
162
+ /'flickr.photos.getSizes' - Photo not found/
163
+ )
164
+ end
165
+ it "raises an error when photo_id is nil" do
166
+ expect {
167
+ flickr.photos.getSizes :photo_id => nil
168
+ }.to raise_error(FlickRaw::FailedResponse)
169
+ end
170
+ end
140
171
  end
141
- it "raises error when garbage given as photo_id" do
142
- expect {
143
- flickr.photos.getSizes :photo_id => 'garbage'
144
- }.to raise_error(
145
- FlickRaw::FailedResponse,
146
- /'flickr.photos.getSizes' - Photo not found/
147
- )
172
+
173
+ specify {flickr_stubs.should respond_to(:interestingness)}
174
+ context "interestingness: stubs flickr.interestingness.getList" do
175
+ before(:each) do
176
+ flickr_stubs.interestingness
177
+ end
178
+ it "returns interesting fixture when no option given" do
179
+ flickr.interestingness.getList.should == fixtures.interesting_photos
180
+ end
181
+ it "returns interesting fixture with non-hash option argument" do
182
+ flickr.interestingness.getList([]).should == fixtures.interesting_photos
183
+ end
184
+ it "returns interesting fixture if hash-option with :date key provided" do
185
+ flickr.interestingness.getList(:tags => 'hello').should == fixtures.interesting_photos
186
+ end
187
+ it "raises error if invalid date provided" do
188
+ expect {
189
+ flickr.interestingness.getList(:date => 'garbage')
190
+ }.to raise_error(
191
+ FlickRaw::FailedResponse,
192
+ /Not a valid date string/
193
+ )
194
+ end
195
+ it "returns empty string if 2001-01-01 given" do
196
+ flickr.interestingness.getList(:date => '2000-01-01').should == fixtures.empty_photos
197
+ end
198
+ it "returns photo details fixture when option given" do
199
+ flickr.interestingness.getList(:date=> '2010-10-10').should == fixtures.interesting_photos
200
+ end
148
201
  end
149
- it "returns photo sizes fixture when option given" do
150
- flickr.photos.getSizes(:secret => '3c4374b19e', :photo_id => "5102817422").should == fixtures.photo_sizes
202
+
203
+ specify {flickr_stubs.should respond_to(:commons_institutions)}
204
+ context "commons_institutions" do
205
+ before(:each) do
206
+ flickr_stubs.commons_institutions
207
+ end
208
+ it "returns commons_institutions fixture" do
209
+ flickr.commons.getInstitutions.should == fixtures.commons_institutions
210
+ end
151
211
  end
152
212
  end
153
213
 
154
- specify {klass.should respond_to(:stub_interestingness)}
155
- context "stub_interestingness: stubs flickr.interestingness.getList" do
156
- before(:each) do
157
- klass.stub_interestingness
158
- end
159
- it "returns interesting fixture when no option given" do
160
- flickr.interestingness.getList.should == fixtures.interesting_photos
161
- end
162
- it "returns interesting fixture with non-hash option argument" do
163
- flickr.interestingness.getList([]).should == fixtures.interesting_photos
164
- end
165
- it "returns interesting fixture if hash-option with :date key provided" do
166
- flickr.interestingness.getList(:tags => 'hello').should == fixtures.interesting_photos
214
+ context "Api stubs" do
215
+ specify {api_stubs.should respond_to :photos}
216
+ context "photos" do
217
+ before(:each) do
218
+ api_stubs.photos
219
+ end
220
+ context "owner_id provided" do
221
+ it "returns object with same user when owner_id provided" do
222
+ params = {:owner_id => '1'}
223
+ api.photos(:owner_id => '1').should ==
224
+ ::FlickrMocks::PhotoSearch.new(fixtures.photos,api.search_params(params))
225
+ end
226
+ it "returns object with same user when owner_id and tags provided" do
227
+ params = {:owner_id => '1',:search_terms => 'iran'}
228
+ api.photos(:owner_id => '1').should ==
229
+ ::FlickrMocks::PhotoSearch.new(fixtures.photos,api.search_params({:owner_id => '1'}))
230
+ end
231
+ it "returns object with no entries when owner_id set to 'garbage'" do
232
+ api.photos(:owner_id => 'garbage').should ==
233
+ ::FlickrMocks::PhotoSearch.new(fixtures.empty_photos,api.search_params({:owner_id => 'garbage'}))
234
+ end
235
+ end
236
+ context "search_terms provided" do
237
+ it "returns object with different owner_id values when :search_terms provided" do
238
+ params = {:search_terms => 'iran'}
239
+ api.photos(params).should ==
240
+ ::FlickrMocks::PhotoSearch.new(fixtures.photos,api.search_params(params))
241
+ end
242
+ it "returns object with no entries when :search_terms is set to 'garbage'" do
243
+ params = {:search_terms => 'garbage'}
244
+ api.photos(params).should ==
245
+ ::FlickrMocks::PhotoSearch.new(fixtures.empty_photos,api.search_params(params))
246
+ end
247
+ end
248
+
249
+ context "error conditions" do
250
+ let(:subject){api}
251
+ let(:method){:photos}
252
+ it_behaves_like "object that expects single Hash argument"
253
+ end
254
+
167
255
  end
168
- it "raises error if invalid date provided" do
169
- expect {
170
- flickr.interestingness.getList(:date => 'garbage')
171
- }.to raise_error(
172
- FlickRaw::FailedResponse,
173
- /Not a valid date string/
174
- )
256
+
257
+ specify {api_stubs.should respond_to :photo_details}
258
+ context "photo_details" do
259
+ before(:each) do
260
+ api_stubs.photo_details
261
+ end
262
+ it "returns expected object when proper :photo_id provided" do
263
+ api.photo_details(:photo_id => '1234').should ==
264
+ ::FlickrMocks::PhotoDetails.new(fixtures.photo_details,fixtures.photo_sizes)
265
+ end
266
+
267
+ context "error conditions" do
268
+ let(:subject){api}
269
+ let(:method){:photo_details}
270
+ it_behaves_like "object that expects single Hash argument"
271
+
272
+ it "raises FlickRaw::FailedResponse when :photo_id not supplied in Hash" do
273
+ expect {
274
+ api.photo_details({})
275
+ }.to raise_error(FlickRaw::FailedResponse)
276
+ end
277
+ it "raises FlickRaw::FailedResponse when :photo_id is nil" do
278
+ expect {
279
+ api.photo_details({:photo_id => nil})
280
+ }.to raise_error(FlickRaw::FailedResponse)
281
+ end
282
+ it "raises FlickRaw::FailedResponse when :photo_id is garbage" do
283
+ expect {
284
+ api.photo_details({:photo_id => 'garbage'})
285
+ }.to raise_error(FlickRaw::FailedResponse)
286
+ end
287
+ end
175
288
  end
176
- it "returns empty string if 2001-01-01 given" do
177
- flickr.interestingness.getList(:date => '2000-01-01').should == fixtures.empty_photos
289
+
290
+ specify {api_stubs.should respond_to :photo}
291
+ context "photo" do
292
+ context "error conditions" do
293
+ end
294
+
178
295
  end
179
- it "returns photo details fixture when option given" do
180
- flickr.interestingness.getList(:date=> '2010-10-10').should == fixtures.interesting_photos
296
+
297
+ specify {api_stubs.should respond_to :photo_sizes}
298
+ context "photo_sizes" do
299
+
181
300
  end
182
- end
301
+
302
+ specify {api_stubs.should respond_to :interesting_photos}
303
+ context "interesting_photos" do
183
304
 
184
- specify {klass.should respond_to(:stub_commons_institutions)}
185
- context "stub_commons_institutions" do
186
- before(:each) do
187
- klass.stub_commons_institutions
188
305
  end
189
- it "returns commons_institutions fixture" do
190
- flickr.commons.getInstitutions.should == fixtures.commons_institutions
306
+
307
+ specify {api_stubs.should respond_to :commons_institutions}
308
+ context "commons_institutions" do
309
+
191
310
  end
311
+
192
312
  end
193
313
 
314
+
194
315
  end
195
316
  end