flickrmocks 0.8.5
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.
- data/.autotest +36 -0
- data/.document +5 -0
- data/.gitignore +23 -0
- data/.rspec +3 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +59 -0
- data/Rakefile +76 -0
- data/VERSION +1 -0
- data/autotest/discover.rb +1 -0
- data/flickrmocks.gemspec +155 -0
- data/lib/flickr_mocks/api/api.rb +42 -0
- data/lib/flickr_mocks/api/flickr.rb +27 -0
- data/lib/flickr_mocks/api/helpers.rb +19 -0
- data/lib/flickr_mocks/api/options.rb +55 -0
- data/lib/flickr_mocks/api/sanitize.rb +29 -0
- data/lib/flickr_mocks/fixtures.rb +35 -0
- data/lib/flickr_mocks/flickraw/custom_clone.rb +19 -0
- data/lib/flickr_mocks/flickraw/custom_compare.rb +25 -0
- data/lib/flickr_mocks/flickraw/custom_marshal.rb +39 -0
- data/lib/flickr_mocks/flickraw/flickraw.rb +14 -0
- data/lib/flickr_mocks/helpers.rb +52 -0
- data/lib/flickr_mocks/models/helpers.rb +14 -0
- data/lib/flickr_mocks/models/photo.rb +101 -0
- data/lib/flickr_mocks/models/photo_details.rb +86 -0
- data/lib/flickr_mocks/models/photo_dimensions.rb +103 -0
- data/lib/flickr_mocks/models/photo_search.rb +115 -0
- data/lib/flickr_mocks/models/photo_size.rb +60 -0
- data/lib/flickr_mocks/models/photo_sizes.rb +93 -0
- data/lib/flickr_mocks/models/photos.rb +133 -0
- data/lib/flickr_mocks/stubs.rb +103 -0
- data/lib/flickr_mocks/version.rb +4 -0
- data/lib/flickrmocks.rb +27 -0
- data/spec/api/api_spec.rb +84 -0
- data/spec/api/flickr_spec.rb +48 -0
- data/spec/api/helper_spec.rb +37 -0
- data/spec/api/options_spec.rb +152 -0
- data/spec/api/sanitize_spec.rb +90 -0
- data/spec/base/fixtures_spec.rb +89 -0
- data/spec/base/flickraw/custom_clone_spec.rb +70 -0
- data/spec/base/flickraw/custom_compare_spec.rb +98 -0
- data/spec/base/flickraw/custom_marshal_spec.rb +45 -0
- data/spec/base/helpers_spec.rb +63 -0
- data/spec/base/stubs_spec.rb +180 -0
- data/spec/base/version_spec.rb +15 -0
- data/spec/fixtures/author_photos.marshal +0 -0
- data/spec/fixtures/empty_photos.marshal +0 -0
- data/spec/fixtures/expected_methods.marshal +17 -0
- data/spec/fixtures/interesting_photos.marshal +0 -0
- data/spec/fixtures/photo.marshal +0 -0
- data/spec/fixtures/photo_details.marshal +0 -0
- data/spec/fixtures/photo_size.marshal +0 -0
- data/spec/fixtures/photo_sizes.marshal +0 -0
- data/spec/fixtures/photos.marshal +0 -0
- data/spec/models/helpers_spec.rb +25 -0
- data/spec/models/photo_details_spec.rb +224 -0
- data/spec/models/photo_dimensions_spec.rb +208 -0
- data/spec/models/photo_search_spec.rb +255 -0
- data/spec/models/photo_size_spec.rb +122 -0
- data/spec/models/photo_sizes_spec.rb +168 -0
- data/spec/models/photo_spec.rb +278 -0
- data/spec/models/photos_spec.rb +305 -0
- data/spec/shared_examples/array_accessor.rb +157 -0
- data/spec/shared_examples/collection.rb +49 -0
- data/spec/shared_examples/image_url_helpers.rb +56 -0
- data/spec/shared_examples/size_accessor.rb +13 -0
- data/spec/spec_helper.rb +24 -0
- data/tasks/fixtures.rb +164 -0
- metadata +259 -0
@@ -0,0 +1,305 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe APP::Photos do
|
5
|
+
let(:api) {APP::Api}
|
6
|
+
let(:klass) {APP::Photos}
|
7
|
+
let(:fixtures){APP::Fixtures.new}
|
8
|
+
let(:photos_fixture) {fixtures.photos}
|
9
|
+
let(:interesting_photos_fixture){fixtures.interesting_photos}
|
10
|
+
|
11
|
+
subject {klass.new photos_fixture}
|
12
|
+
let(:max_pages){subject.default(:max_entries)/subject.default(:per_page)}
|
13
|
+
|
14
|
+
context "class methods" do
|
15
|
+
specify { klass.should respond_to(:defaults)}
|
16
|
+
|
17
|
+
context "defaults" do
|
18
|
+
before(:each) do
|
19
|
+
@defaults = klass.defaults.clone
|
20
|
+
end
|
21
|
+
after(:each) do
|
22
|
+
klass.defaults = @defaults
|
23
|
+
end
|
24
|
+
specify {klass.defaults.should have_key(:max_entries)}
|
25
|
+
specify {klass.defaults.should have_key(:per_page)}
|
26
|
+
|
27
|
+
it "should behave like a Hash" do
|
28
|
+
klass.defaults.keys.each do |key|
|
29
|
+
setter = (key.to_s + '=').to_sym
|
30
|
+
value = klass.defaults.send(:[],key)
|
31
|
+
expected = value*2
|
32
|
+
klass.defaults.send(:[]=,key,expected)
|
33
|
+
klass.defaults.send(:[],key).should == expected
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "class instance variables" do
|
40
|
+
context "@defaults" do
|
41
|
+
specify { klass.defaults.should have_key(:max_entries) }
|
42
|
+
specify { klass.defaults.should have_key(:per_page) }
|
43
|
+
|
44
|
+
it "returns 50 for argument :per_page" do
|
45
|
+
klass.defaults[:per_page].should == 50
|
46
|
+
end
|
47
|
+
it "returns 4000 for argument :max_entries" do
|
48
|
+
klass.defaults[:max_entries].should == 4000
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
context "initialization" do
|
55
|
+
it "returns object of a proper class when photos FlickRaw::ResponseList provided" do
|
56
|
+
klass.new(fixtures.photos).class.should == klass
|
57
|
+
end
|
58
|
+
it "raises an error when FlickRaw::Response provided" do
|
59
|
+
expect {klass.new(fixtures.photo)}.to raise_error(ArgumentError)
|
60
|
+
end
|
61
|
+
it "raises an error when an Array class specified" do
|
62
|
+
expect {klass.new([1,2,3,4])}.to raise_error(ArgumentError)
|
63
|
+
end
|
64
|
+
it "raises an error when sizes FlickRaw::ResponseList provided" do
|
65
|
+
expect {klass.new(fixtures.sizes)}.to raise_error
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "instance methods" do
|
70
|
+
specify { subject.should respond_to(:default) }
|
71
|
+
context "#default" do
|
72
|
+
it "accepts a string for argument" do
|
73
|
+
klass.defaults.each_pair do |key,value|
|
74
|
+
subject.default(key.to_s).should == value
|
75
|
+
end
|
76
|
+
end
|
77
|
+
it "accepts a symbol for argument" do
|
78
|
+
klass.defaults.each_pair do |key,value|
|
79
|
+
subject.default(key.to_sym).should == value
|
80
|
+
end
|
81
|
+
end
|
82
|
+
it "returns 50 for :per_page" do
|
83
|
+
subject.default(:per_page).should == klass.defaults[:per_page]
|
84
|
+
end
|
85
|
+
it "returns 4000 for :max_entries" do
|
86
|
+
subject.default(:max_entries).should == klass.defaults[:max_entries]
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
specify { subject.should respond_to(:current_page) }
|
91
|
+
context "#current_page" do
|
92
|
+
it "returns expected page" do
|
93
|
+
subject.current_page.should == photos_fixture.page
|
94
|
+
end
|
95
|
+
it "returns kind of type Fixnum" do
|
96
|
+
subject.current_page.should be_a(Fixnum)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
specify { subject.should respond_to(:per_page) }
|
101
|
+
describe "#per_page" do
|
102
|
+
it "returns maximum entries possible for a page" do
|
103
|
+
subject.per_page.should == photos_fixture.perpage
|
104
|
+
end
|
105
|
+
it "returns kind of Fixnum" do
|
106
|
+
subject.per_page.should be_a(Fixnum)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
specify { subject.should respond_to(:perpage) }
|
111
|
+
describe "#perpage" do
|
112
|
+
it "returns maximum entries possible for a page" do
|
113
|
+
subject.perpage.should == photos_fixture.perpage
|
114
|
+
end
|
115
|
+
it "returns kind of Fixnum" do
|
116
|
+
subject.perpage.should be_a(Fixnum)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
specify { subject.should respond_to(:total_entries) }
|
121
|
+
describe "#total_entries" do
|
122
|
+
it "returns total of photos" do
|
123
|
+
subject.total_entries.should == photos_fixture.total.to_i
|
124
|
+
end
|
125
|
+
specify{ subject.total_entries.should be_a(Fixnum)}
|
126
|
+
end
|
127
|
+
|
128
|
+
specify {subject.should respond_to(:capped_entries)}
|
129
|
+
describe "#capped_entries" do
|
130
|
+
it "returns total_entries when total_entries <= max_entries" do
|
131
|
+
subject.stub(:total_entries).and_return(subject.max_entries)
|
132
|
+
subject.capped_entries.should == subject.total_entries
|
133
|
+
end
|
134
|
+
it "returns max_entries when total_entries > max_entries" do
|
135
|
+
subject.stub(:total_entries).and_return(subject.max_entries + 200)
|
136
|
+
subject.capped_entries.should < subject.total_entries
|
137
|
+
subject.capped_entries.should == subject.max_entries
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
specify { subject.should respond_to(:max_entries) }
|
142
|
+
describe "#max_entries" do
|
143
|
+
it "returns maximum possible entries returned by flickr" do
|
144
|
+
subject.max_entries.should == subject.default(:max_entries)
|
145
|
+
end
|
146
|
+
it "returns kind of Fixnum" do
|
147
|
+
subject.max_entries.should be_a(Fixnum)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
specify { subject.should respond_to(:pages) }
|
152
|
+
describe "#pages" do
|
153
|
+
it "limits the number of pages when total_pages > max_pages" do
|
154
|
+
subject.stub(:total_pages).and_return(max_pages+20)
|
155
|
+
subject.pages.should == max_pages
|
156
|
+
end
|
157
|
+
it "returns total pages when total_pages <= max_pages" do
|
158
|
+
pages = max_pages() - 1
|
159
|
+
subject.stub(:total_pages).and_return(pages)
|
160
|
+
subject.pages.should == pages
|
161
|
+
end
|
162
|
+
it "returns kind of Fixnum" do
|
163
|
+
subject.pages.should be_a(Fixnum)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
specify { subject.should respond_to(:capped?) }
|
168
|
+
describe "#capped?" do
|
169
|
+
it "returns true when partial number of entries returned" do
|
170
|
+
subject.stub(:total_entries).and_return(subject.default(:max_entries)+1)
|
171
|
+
subject.should be_capped
|
172
|
+
end
|
173
|
+
it "returns false when all entries returned" do
|
174
|
+
subject.stub(:total_entries).and_return(subject.default(:max_entries))
|
175
|
+
subject.should_not be_capped
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
specify { subject.should respond_to(:photos) }
|
180
|
+
describe "#photos" do
|
181
|
+
it "returns kind of Array" do
|
182
|
+
subject.photos.should be_an(Array)
|
183
|
+
end
|
184
|
+
it "returns Array containing elements of class FlickrMocks::Photo " do
|
185
|
+
subject.photos.each do |photo|
|
186
|
+
photo.should be_instance_of(APP::Photo)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
it "returns expected number of photos" do
|
190
|
+
subject.photos.length.should == fixtures.photos.map(&:id).length
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
|
195
|
+
specify {subject.should respond_to(:==)}
|
196
|
+
context "#==" do
|
197
|
+
it "returns true when comparing object to self" do
|
198
|
+
subject.should == subject
|
199
|
+
end
|
200
|
+
it "returns true when comparing object to clone of self" do
|
201
|
+
subject.should == subject.clone
|
202
|
+
end
|
203
|
+
it "returns false when object compared to random object" do
|
204
|
+
subject.should_not == [1,2,3,4]
|
205
|
+
end
|
206
|
+
it "returns false when object compard to nil" do
|
207
|
+
subject.should_not == nil
|
208
|
+
end
|
209
|
+
it "returns false when object compared to object that is different in only one element" do
|
210
|
+
other = subject.clone
|
211
|
+
other.photos.last.instance_eval('@delegated_to_object').instance_eval('@h["farm"]=1234321')
|
212
|
+
subject.should_not == other
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
specify {subject.should respond_to(:collection)}
|
217
|
+
context "#collection" do
|
218
|
+
context "usable argument set to nil" do
|
219
|
+
let(:reference){
|
220
|
+
OpenStruct.new :current_page => subject.current_page,
|
221
|
+
:per_page => subject.per_page,
|
222
|
+
:total_entries => subject.capped_entries,
|
223
|
+
:collection => subject.photos
|
224
|
+
}
|
225
|
+
it_behaves_like "object that responds to collection"
|
226
|
+
end
|
227
|
+
|
228
|
+
context "usable argument set to true" do
|
229
|
+
subject {klass.new(interesting_photos_fixture)}
|
230
|
+
let(:collection){subject.photos.clone.keep_if do |p| p.license.to_i > 3 end}
|
231
|
+
let(:reference) {
|
232
|
+
OpenStruct.new :current_page => 1,
|
233
|
+
:per_page => subject.perpage,
|
234
|
+
:total_entries => collection.length,
|
235
|
+
:collection => collection
|
236
|
+
}
|
237
|
+
it_behaves_like "object that responds to collection with usable option"
|
238
|
+
end
|
239
|
+
|
240
|
+
context "empty collection" do
|
241
|
+
let(:reference) {
|
242
|
+
OpenStruct.new :current_page => 1,
|
243
|
+
:per_page => fixtures.empty_photos.perpage,
|
244
|
+
:total_entries => 0,
|
245
|
+
:collection => []
|
246
|
+
}
|
247
|
+
let(:subject){klass.new(fixtures.empty_photos)}
|
248
|
+
it_behaves_like "object with no items that responds to collection"
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
specify {subject.should respond_to(:usable_photos)}
|
253
|
+
context "#usable_items" do
|
254
|
+
it "returns all items if every item is usable" do
|
255
|
+
subject.usable_photos == subject.photos
|
256
|
+
end
|
257
|
+
it "returns subset of items if not all items are usable" do
|
258
|
+
subject.usable_photos == subject.photos.clone.keep_if(&:usable?)
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
context "meta-programming" do
|
263
|
+
specify{ subject.should respond_to(:delegated_instance_methods)}
|
264
|
+
context "#delegated_instance_methods" do
|
265
|
+
it "returns expected list of methods that are delegated to other objects" do
|
266
|
+
subject.delegated_instance_methods.should == APP::Models::Helpers.array_accessor_methods
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
specify { subject.should respond_to(:methods)}
|
271
|
+
context "#methods" do
|
272
|
+
it "should return all methods as well as array iteration methods" do
|
273
|
+
subject.methods.sort.should == (subject.old_methods + subject.delegated_instance_methods).sort
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
specify{ subject.should respond_to(:respond_to?)}
|
278
|
+
context "#respond_to?" do
|
279
|
+
it "recognizes all methods returned by #methods" do
|
280
|
+
subject.methods.each do |method|
|
281
|
+
subject.should respond_to(method)
|
282
|
+
end
|
283
|
+
end
|
284
|
+
end
|
285
|
+
context "iteratable methods" do
|
286
|
+
let(:reference) {subject.photos}
|
287
|
+
it_behaves_like "object with delegated Array accessor helpers"
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
context "custom cloning methods" do
|
292
|
+
context "#initialize_copy" do
|
293
|
+
it "returns photo objects that have distinct ids from the cloned object" do
|
294
|
+
other = subject.clone
|
295
|
+
index = 0
|
296
|
+
subject.photos.each do |photo|
|
297
|
+
photo.__id__.should_not == other.photos[index].__id__
|
298
|
+
index += 1
|
299
|
+
end
|
300
|
+
end
|
301
|
+
end
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
end
|
@@ -0,0 +1,157 @@
|
|
1
|
+
shared_examples_for "object with delegated Array accessor helpers" do
|
2
|
+
# NOTE: need to define:
|
3
|
+
# => subject : that returns item under test, which has accessor
|
4
|
+
# => references : object that gets delegated to
|
5
|
+
specify{subject.should respond_to(:[])}
|
6
|
+
specify{subject.should respond_to(:at)}
|
7
|
+
specify{subject.should respond_to(:fetch)}
|
8
|
+
specify{subject.should respond_to(:first)}
|
9
|
+
specify{subject.should respond_to(:last)}
|
10
|
+
specify{subject.should respond_to(:each)}
|
11
|
+
specify{subject.should respond_to(:each_index)}
|
12
|
+
specify{subject.should respond_to(:reverse_each)}
|
13
|
+
specify{subject.should respond_to(:length)}
|
14
|
+
specify{subject.should respond_to(:size)}
|
15
|
+
specify{subject.should respond_to(:empty?)}
|
16
|
+
specify{subject.should respond_to(:find_index)}
|
17
|
+
specify{subject.should respond_to(:index)}
|
18
|
+
specify{subject.should respond_to(:rindex)}
|
19
|
+
specify{subject.should respond_to(:collect)}
|
20
|
+
specify{subject.should respond_to(:map)}
|
21
|
+
specify{subject.should respond_to(:select)}
|
22
|
+
specify{subject.should respond_to(:keep_if)}
|
23
|
+
specify{subject.should respond_to(:values_at)}
|
24
|
+
|
25
|
+
context "#[]" do
|
26
|
+
it "returns same reference for index 0" do
|
27
|
+
subject[0].should == reference[0]
|
28
|
+
end
|
29
|
+
it "returns same reference for index -1" do
|
30
|
+
subject[-1].should == reference[-1]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "#at" do
|
35
|
+
it "returns same as reference element 0" do
|
36
|
+
subject.at(0).should == reference.at(0)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "#values_at" do
|
41
|
+
it "returns same value as element 0" do
|
42
|
+
subject.values_at(0).should == reference.values_at(0)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "#fetch" do
|
47
|
+
it "returns same as reference for element 0" do
|
48
|
+
subject.fetch(0).should == reference.fetch(0)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "#first" do
|
53
|
+
it "returns same element as reference" do
|
54
|
+
subject.first == reference.first
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "#last" do
|
59
|
+
it "returns same element as reference" do
|
60
|
+
subject.last == reference.last
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "#length" do
|
65
|
+
it "returns same value as reference" do
|
66
|
+
subject.length.should == reference.length
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context "#size" do
|
71
|
+
it "returns same value as reference" do
|
72
|
+
subject.size.should == reference.size
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context "#find_index" do
|
77
|
+
it "returns same index as reference" do
|
78
|
+
subject.find_index(subject[0]).should == reference.find_index(subject[0])
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context "#index" do
|
83
|
+
it "returns same index as reference" do
|
84
|
+
subject.index(subject[0]).should == reference.index(subject[0])
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context "#empty?" do
|
89
|
+
it "returns same value as reference" do
|
90
|
+
subject.empty?.should == reference.empty?
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context "#each" do
|
95
|
+
it "returns same list as reference" do
|
96
|
+
actual = []
|
97
|
+
expected =[]
|
98
|
+
subject.each {|v| actual.push v}
|
99
|
+
reference.each{|v| expected.push v}
|
100
|
+
actual.should == expected
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
|
105
|
+
context "#each_index" do
|
106
|
+
it "returns same list as reference" do
|
107
|
+
compare_iterator(:each_index)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context "#reverse_each" do
|
112
|
+
it "returns same list as reference" do
|
113
|
+
compare_iterator(:reverse_each)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
context "#rindex" do
|
118
|
+
it "returns same list as reference" do
|
119
|
+
compare_iterator(:rindex)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
context "#select" do
|
124
|
+
it "returns same list as reference" do
|
125
|
+
actual = []
|
126
|
+
expected = []
|
127
|
+
subject.select {|v| true }.should == reference.select {|v| true }
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
context "#collect" do
|
132
|
+
it "returns same as reference" do
|
133
|
+
subject.collect { |v| v }.should == reference.collect { |v| v }
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
context "#map" do
|
138
|
+
it "returns same as reference" do
|
139
|
+
subject.map {|v| v.__id__ }.should == reference.map { |v| v.__id__ }
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
context "#keep_if" do
|
144
|
+
it "returns same as reference" do
|
145
|
+
subject.keep_if {|v| true}.should == reference.keep_if {|v| true}
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
private
|
150
|
+
|
151
|
+
def compare_iterator(method)
|
152
|
+
actual = []
|
153
|
+
expected = []
|
154
|
+
subject.send(method) {|v| actual.push(v) }.should == reference.send(method) { |v| expected.push(v) }
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# subject is object under test
|
2
|
+
# reference is an object that responds to: :current_page,:per_page,:total_entries,:collection
|
3
|
+
shared_examples_for "object that responds to collection" do
|
4
|
+
specify {subject.collection.class.should == WillPaginate::Collection}
|
5
|
+
it "returns object with expected current_page" do
|
6
|
+
subject.collection.current_page.should == reference.current_page
|
7
|
+
end
|
8
|
+
it "returns object with expected per_page" do
|
9
|
+
subject.collection.per_page.should == reference.per_page
|
10
|
+
end
|
11
|
+
it "returns object with expected total_entries" do
|
12
|
+
subject.collection.total_entries.should == reference.total_entries
|
13
|
+
end
|
14
|
+
it "returns object with expected elements" do
|
15
|
+
subject.collection.map do |item| item end.should == reference.collection.map do |item| item end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
shared_examples_for "object with no items that responds to collection" do
|
20
|
+
specify {subject.should respond_to(:collection)}
|
21
|
+
it "returns object with expected current_page" do
|
22
|
+
subject.collection.current_page.should == reference.current_page
|
23
|
+
end
|
24
|
+
it "returns object with expected per_page" do
|
25
|
+
subject.collection.per_page.should == reference.per_page
|
26
|
+
end
|
27
|
+
it "returns object with expected total_entries" do
|
28
|
+
subject.collection.total_entries.should == reference.total_entries
|
29
|
+
end
|
30
|
+
it "returns object with no elements" do
|
31
|
+
subject.collection.should == reference.collection
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
shared_examples_for "object that responds to collection with usable option" do
|
36
|
+
specify {subject.collection(true).class.should == WillPaginate::Collection}
|
37
|
+
it "returns collection that includes only usable photos" do
|
38
|
+
subject.collection(true).should == reference.collection
|
39
|
+
end
|
40
|
+
it "returns object with current_page set to 1" do
|
41
|
+
subject.collection(true).current_page.should == reference.current_page
|
42
|
+
end
|
43
|
+
it "returns object with total_entries set to number of usable entries in current page" do
|
44
|
+
subject.collection(true).total_entries.should == reference.total_entries
|
45
|
+
end
|
46
|
+
it "returns object with per_page set ot number of usable entries on current page" do
|
47
|
+
subject.collection(true).per_page.should == reference.per_page
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
shared_examples_for "object with flickr image url helpers" do
|
2
|
+
specify {subject.should respond_to(:square)}
|
3
|
+
let(:base_url){"http://farm%s.static.flickr.com/%s/%s_%s" %[
|
4
|
+
subject.farm,
|
5
|
+
subject.server,
|
6
|
+
subject.id,
|
7
|
+
subject.secret
|
8
|
+
]}
|
9
|
+
context "#square" do
|
10
|
+
it "returns expected url for squre flickr image" do
|
11
|
+
subject.square.should == "#{base_url}_s.jpg"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
specify {subject.should respond_to(:thumbnail)}
|
16
|
+
context "#thumbnail_url" do
|
17
|
+
it "returns expected url for thumbnail image" do
|
18
|
+
subject.thumbnail.should == "#{base_url}_t.jpg"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
specify {subject.should respond_to(:small)}
|
23
|
+
context "#small" do
|
24
|
+
it "returns expected url for small image" do
|
25
|
+
subject.small.should == "#{base_url}_m.jpg"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
specify {subject.should respond_to(:medium)}
|
30
|
+
context "#medium" do
|
31
|
+
it "returns expected url for medium" do
|
32
|
+
subject.medium.should == "#{base_url}.jpg"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
specify {subject.should respond_to(:large)}
|
37
|
+
context "#large" do
|
38
|
+
it "returns expected url for large image" do
|
39
|
+
subject.large.should == "#{base_url}_b.jpg"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
specify {subject.should respond_to(:medium_640)}
|
44
|
+
context "#medium_640" do
|
45
|
+
it "returns expected url for medium 640 image" do
|
46
|
+
subject.medium_640.should == "#{base_url}_z.jpg"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
specify {subject.should respond_to(:'medium 640')}
|
51
|
+
context "#'medium 640'" do
|
52
|
+
it "returns expected url for medium 640 image" do
|
53
|
+
subject.send(:'medium 640').should == "#{base_url}_z.jpg"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
shared_examples_for "object with size accessor" do
|
2
|
+
it "returns object with expected size" do
|
3
|
+
subject.send(size).size.should == reference.size
|
4
|
+
end
|
5
|
+
|
6
|
+
it "returns object with expected width" do
|
7
|
+
subject.send(size).width.should == reference.width
|
8
|
+
end
|
9
|
+
|
10
|
+
it "returns object with expected height" do
|
11
|
+
subject.send(size).height.should == reference.height
|
12
|
+
end
|
13
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rspec'
|
3
|
+
|
4
|
+
require 'faker'
|
5
|
+
|
6
|
+
require 'chronic_duration'
|
7
|
+
require 'flickraw-cached'
|
8
|
+
require 'ruby-debug'
|
9
|
+
|
10
|
+
require 'shared_examples/array_accessor'
|
11
|
+
require 'shared_examples/image_url_helpers'
|
12
|
+
require 'shared_examples/size_accessor'
|
13
|
+
require 'shared_examples/collection'
|
14
|
+
|
15
|
+
require 'flickrmocks'
|
16
|
+
|
17
|
+
Rspec.configure do |c|
|
18
|
+
# c.mock_with :mocha
|
19
|
+
|
20
|
+
APP = FlickrMocks
|
21
|
+
FlickrFixtures = APP::Fixtures.new
|
22
|
+
end
|
23
|
+
|
24
|
+
|