cineworld_uk 1.0.5 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/CHANGELOG.md +64 -0
  4. data/README.md +2 -1
  5. data/cineworld_uk.gemspec +3 -3
  6. data/lib/cineworld_uk/cinema.rb +60 -69
  7. data/lib/cineworld_uk/film.rb +25 -7
  8. data/lib/cineworld_uk/internal/film_with_screenings_parser.rb +29 -71
  9. data/lib/cineworld_uk/internal/name_parser.rb +20 -18
  10. data/lib/cineworld_uk/internal/screening_parser.rb +132 -0
  11. data/lib/cineworld_uk/internal/titleize.rb +19 -19
  12. data/lib/cineworld_uk/internal/website.rb +33 -0
  13. data/lib/cineworld_uk/internal/whatson_parser.rb +44 -0
  14. data/lib/cineworld_uk/screening.rb +65 -20
  15. data/lib/cineworld_uk/version.rb +2 -2
  16. data/lib/cineworld_uk.rb +4 -0
  17. data/test/fixture_updater.rb +64 -0
  18. data/test/fixtures/cinemas.html +134 -41
  19. data/test/fixtures/{cinemas/bury-st-edmunds.html → information/brighton.html} +488 -437
  20. data/test/fixtures/{cinemas → information}/bristol.html +463 -410
  21. data/test/fixtures/whatson/brighton/film_first.html +775 -0
  22. data/test/fixtures/whatson/brighton/film_last.html +52 -0
  23. data/test/fixtures/whatson/brighton/film_second.html +645 -0
  24. data/test/fixtures/whatson/brighton.html +3564 -2690
  25. data/test/fixtures/whatson/glasgow-imax-at-gsc/film_first.html +140 -0
  26. data/test/fixtures/whatson/the-o2-greenwich/film_first.html +1242 -0
  27. data/test/lib/cineworld_uk/cinema_test.rb +104 -301
  28. data/test/lib/cineworld_uk/film_test.rb +49 -2
  29. data/test/lib/cineworld_uk/internal/film_with_screenings_parser_test.rb +83 -81
  30. data/test/lib/cineworld_uk/internal/titleize_test.rb +12 -5
  31. data/test/lib/cineworld_uk/internal/website_test.rb +57 -0
  32. data/test/lib/cineworld_uk/internal/whatson_parser_test.rb +58 -0
  33. data/test/lib/cineworld_uk/screening_test.rb +155 -23
  34. data/test/lib/cineworld_uk/version_test.rb +1 -1
  35. data/test/test_helper.rb +3 -1
  36. metadata +30 -33
  37. data/test/fixtures/cinemas/brighton.html +0 -8
  38. data/test/fixtures/cinemas/chelsea.html +0 -1030
  39. data/test/fixtures/cinemas/glasgow-imax-at-gsc.html +0 -916
  40. data/test/fixtures/cinemas/the-o2-grenwich.html +0 -1191
  41. data/test/fixtures/whatson/brighton/gravity.html +0 -2129
  42. data/test/fixtures/whatson/glasgow-imax-at-gsc/the-hunger-games-catching-fire.html +0 -498
  43. data/test/fixtures/whatson/glasgow-imax-at-gsc-cinema.html +0 -3160
  44. data/test/fixtures/whatson/the-o2-greenwich/gravity.html +0 -784
  45. data/test/fixtures/whatson/the-o2-greenwich/the-hobbit-desolation-of-smaug.html +0 -764
  46. data/test/fixtures/whatson/the-o2-greenwich.html +0 -6854
  47. data/test/fixtures/whatson/wandsworth.html +0 -13729
@@ -1,60 +1,58 @@
1
1
  require_relative '../../test_helper'
2
2
 
3
3
  describe CineworldUk::Cinema do
4
+ let(:website) { Minitest::Mock.new }
4
5
 
5
- before { WebMock.disable_net_connect! }
6
+ before do
7
+ WebMock.disable_net_connect!
8
+ end
6
9
 
7
10
  describe '.all' do
8
11
  subject { CineworldUk::Cinema.all }
9
12
 
10
13
  before do
11
- body = File.read( File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'cinemas.html') )
12
- stub_request(:get, 'http://www.cineworld.co.uk/cinemas').to_return( status: 200, body: body, headers: {} )
14
+ website.expect(:cinemas, cinemas_html)
13
15
  end
14
16
 
15
17
  it 'returns an Array of CineworldUK::Cinemas' do
16
- subject.must_be_instance_of(Array)
17
- subject.each do |value|
18
- value.must_be_instance_of(CineworldUk::Cinema)
18
+ CineworldUk::Internal::Website.stub :new, website do
19
+ subject.must_be_instance_of(Array)
20
+ subject.each do |value|
21
+ value.must_be_instance_of(CineworldUk::Cinema)
22
+ end
19
23
  end
20
24
  end
21
25
 
22
26
  it 'returns the correctly sized array' do
23
- subject.size.must_equal 81
27
+ CineworldUk::Internal::Website.stub :new, website do
28
+ subject.size.must_equal 82
29
+ end
24
30
  end
25
31
  end
26
32
 
27
33
  describe '.find(id)' do
28
34
  subject { CineworldUk::Cinema.find(id) }
29
35
 
30
- before do
31
- body = File.read( File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'cinemas.html') )
32
- stub_request(:get, 'http://www.cineworld.co.uk/cinemas').to_return( status: 200, body: body, headers: {} )
33
- end
34
-
35
36
  describe 'Brighton' do
36
37
  let(:id) { 3 }
37
38
 
39
+ before do
40
+ website.expect(:cinemas, cinemas_html)
41
+ end
42
+
38
43
  it 'returns a cinema' do
39
- subject.must_be_instance_of(CineworldUk::Cinema)
44
+ CineworldUk::Internal::Website.stub :new, website do
45
+ subject.must_be_instance_of(CineworldUk::Cinema)
40
46
 
41
- subject.id.must_equal 3
42
- subject.brand.must_equal 'Cineworld'
43
- subject.name.must_equal 'Brighton'
47
+ subject.id.must_equal 3
48
+ subject.brand.must_equal 'Cineworld'
49
+ subject.name.must_equal 'Brighton'
50
+ end
44
51
  end
45
52
  end
46
53
  end
47
54
 
48
- describe '.new id, name, url' do
49
- it 'stores id, name, slug and url' do
50
- cinema = CineworldUk::Cinema.new '3', 'Brighton'
51
- cinema.id.must_equal 3
52
- cinema.brand.must_equal 'Cineworld'
53
- cinema.name.must_equal 'Brighton'
54
- cinema.slug.must_equal 'brighton'
55
- cinema.url.must_equal 'http://www.cineworld.co.uk/cinemas/3/information'
56
- end
57
-
55
+ describe '.new' do
58
56
  it 'removes "London - " name prefix' do
59
57
  cinema = CineworldUk::Cinema.new 79, 'London - The O2, Greenwich'
60
58
  cinema.id.must_equal 79
@@ -77,19 +75,20 @@ describe CineworldUk::Cinema do
77
75
  let(:cinema) { CineworldUk::Cinema.new('3', 'Brighton') }
78
76
 
79
77
  before do
80
- body = File.read( File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'cinemas', 'brighton.html') )
81
- stub_request(:get, 'http://www.cineworld.co.uk/cinemas/3/information').to_return( status: 200, body: body, headers: {} )
78
+ website.expect(:information, information_html('brighton'), [3])
82
79
  end
83
80
 
84
81
  it 'returns the address hash' do
85
- subject.must_equal({
86
- street_address: 'Brighton Marina',
87
- extended_address: nil,
88
- locality: 'Brighton',
89
- region: 'East Sussex',
90
- postal_code: 'BN2 5UF',
91
- country: 'United Kingdom'
92
- })
82
+ CineworldUk::Internal::Website.stub :new, website do
83
+ subject.must_equal(
84
+ street_address: 'Brighton Marina',
85
+ extended_address: nil,
86
+ locality: 'Brighton',
87
+ region: 'East Sussex',
88
+ postal_code: 'BN2 5UF',
89
+ country: 'United Kingdom'
90
+ )
91
+ end
93
92
  end
94
93
  end
95
94
 
@@ -97,79 +96,20 @@ describe CineworldUk::Cinema do
97
96
  let(:cinema) { CineworldUk::Cinema.new('4', 'Bristol') }
98
97
 
99
98
  before do
100
- body = File.read( File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'cinemas', 'bristol.html') )
101
- stub_request(:get, 'http://www.cineworld.co.uk/cinemas/4/information').to_return( status: 200, body: body, headers: {} )
102
- end
103
-
104
- it 'returns the address hash' do
105
- subject.must_equal({
106
- street_address: 'Hengrove Leisure Park',
107
- extended_address: 'Hengrove Way',
108
- locality: 'Bristol',
109
- region: nil,
110
- postal_code: 'BS14 0HR',
111
- country: 'United Kingdom'
112
- })
113
- end
114
- end
115
-
116
- describe '(bury st edmunds)' do
117
- let(:cinema) { CineworldUk::Cinema.new('6', 'Bury St. Edmunds') }
118
-
119
- before do
120
- body = File.read( File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'cinemas', 'bury-st-edmunds.html') )
121
- stub_request(:get, 'http://www.cineworld.co.uk/cinemas/6/information').to_return( status: 200, body: body, headers: {} )
122
- end
123
-
124
- it 'returns the address hash' do
125
- subject.must_equal({
126
- street_address: 'Parkway',
127
- extended_address: nil,
128
- locality: 'Bury St. Edmunds',
129
- region: nil,
130
- postal_code: 'IP33 3BA',
131
- country: 'United Kingdom'
132
- })
133
- end
134
- end
135
-
136
- describe '(london chelsea)' do
137
- let(:cinema) { CineworldUk::Cinema.new('10', 'London - Chelsea') }
138
-
139
- before do
140
- body = File.read( File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'cinemas', 'chelsea.html') )
141
- stub_request(:get, 'http://www.cineworld.co.uk/cinemas/10/information').to_return( status: 200, body: body, headers: {} )
142
- end
143
-
144
- it 'returns the address hash' do
145
- subject.must_equal({
146
- street_address: '279 Kings Road',
147
- extended_address: 'Chelsea',
148
- locality: 'London',
149
- region: nil,
150
- postal_code: 'SW3 5EW',
151
- country: 'United Kingdom'
152
- })
153
- end
154
- end
155
-
156
- describe '(london o2)' do
157
- let(:cinema) { CineworldUk::Cinema.new('79', 'The O2, Grenwich') }
158
-
159
- before do
160
- body = File.read( File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'cinemas', 'the-o2-grenwich.html') )
161
- stub_request(:get, 'http://www.cineworld.co.uk/cinemas/79/information').to_return( status: 200, body: body, headers: {} )
99
+ website.expect(:information, information_html('bristol'), [4])
162
100
  end
163
101
 
164
102
  it 'returns the address hash' do
165
- subject.must_equal({
166
- street_address: 'The O2',
167
- extended_address: 'Peninsula Square',
168
- locality: 'London',
169
- region: nil,
170
- postal_code: 'SE10 0DX',
171
- country: 'United Kingdom'
172
- })
103
+ CineworldUk::Internal::Website.stub :new, website do
104
+ subject.must_equal(
105
+ street_address: 'Hengrove Leisure Park',
106
+ extended_address: 'Hengrove Way',
107
+ locality: 'Bristol',
108
+ region: nil,
109
+ postal_code: 'BS14 0HR',
110
+ country: 'United Kingdom'
111
+ )
112
+ end
173
113
  end
174
114
  end
175
115
  end
@@ -181,12 +121,13 @@ describe CineworldUk::Cinema do
181
121
  let(:cinema) { CineworldUk::Cinema.new('3', 'Brighton') }
182
122
 
183
123
  before do
184
- body = File.read( File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'cinemas', 'brighton.html') )
185
- stub_request(:get, 'http://www.cineworld.co.uk/cinemas/3/information').to_return( status: 200, body: body, headers: {} )
124
+ website.expect(:information, information_html('brighton'), [3])
186
125
  end
187
126
 
188
127
  it 'returns nil' do
189
- subject.must_be_nil
128
+ CineworldUk::Internal::Website.stub :new, website do
129
+ subject.must_be_nil
130
+ end
190
131
  end
191
132
  end
192
133
 
@@ -194,90 +135,25 @@ describe CineworldUk::Cinema do
194
135
  let(:cinema) { CineworldUk::Cinema.new('4', 'Bristol') }
195
136
 
196
137
  before do
197
- body = File.read( File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'cinemas', 'bristol.html') )
198
- stub_request(:get, 'http://www.cineworld.co.uk/cinemas/4/information').to_return( status: 200, body: body, headers: {} )
199
- end
200
-
201
- it 'returns the second line' do
202
- subject.must_equal 'Hengrove Way'
203
- end
204
- end
205
-
206
- describe '(bury st edmunds)' do
207
- let(:cinema) { CineworldUk::Cinema.new('6', 'Bury St. Edmunds') }
208
-
209
- before do
210
- body = File.read( File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'cinemas', 'bury-st-edmunds.html') )
211
- stub_request(:get, 'http://www.cineworld.co.uk/cinemas/6/information').to_return( status: 200, body: body, headers: {} )
212
- end
213
-
214
- it 'returns the town/city' do
215
- subject.must_be_nil
216
- end
217
- end
218
-
219
- describe '(london chelsea)' do
220
- let(:cinema) { CineworldUk::Cinema.new('10', 'London - Chelsea') }
221
-
222
- before do
223
- body = File.read( File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'cinemas', 'chelsea.html') )
224
- stub_request(:get, 'http://www.cineworld.co.uk/cinemas/10/information').to_return( status: 200, body: body, headers: {} )
138
+ website.expect(:information, information_html('bristol'), [4])
225
139
  end
226
140
 
227
141
  it 'returns the second line' do
228
- subject.must_equal 'Chelsea'
229
- end
230
- end
231
-
232
- describe '(london o2)' do
233
- let(:cinema) { CineworldUk::Cinema.new('79', 'The O2, Grenwich') }
234
-
235
- before do
236
- body = File.read( File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'cinemas', 'the-o2-grenwich.html') )
237
- stub_request(:get, 'http://www.cineworld.co.uk/cinemas/79/information').to_return( status: 200, body: body, headers: {} )
238
- end
239
-
240
- it 'returns the second line' do
241
- subject.must_equal 'Peninsula Square'
142
+ CineworldUk::Internal::Website.stub :new, website do
143
+ subject.must_equal 'Hengrove Way'
144
+ end
242
145
  end
243
146
  end
244
147
  end
245
148
 
246
149
  describe '#films' do
247
- let(:cinema) { CineworldUk::Cinema.new('3', 'Brighton') }
248
- subject { cinema.films }
150
+ subject { CineworldUk::Cinema.new('3', 'Brighton').films }
249
151
 
250
- before do
251
- body = File.read( File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'whatson', 'brighton.html') )
252
- stub_request(:get, 'http://www.cineworld.co.uk/whatson?cinema=3').to_return( status: 200, body: body, headers: {} )
253
- end
254
-
255
- it 'returns an array of films' do
256
- subject.must_be_instance_of(Array)
257
- subject.each do |item|
258
- item.must_be_instance_of(CineworldUk::Film)
259
- end
260
- end
261
-
262
- it 'returns correct number of films' do
263
- subject.count.must_equal 24
264
- end
265
-
266
- it 'returns uniquely named films' do
267
- subject.each_with_index do |item, index|
268
- subject.each_with_index do |jtem, i|
269
- if index != i
270
- item.name.wont_equal jtem.name
271
- item.wont_equal jtem
272
- end
273
- end
152
+ it 'calls out to Screening object' do
153
+ CineworldUk::Film.stub :at, [:film] do
154
+ subject.must_equal([:film])
274
155
  end
275
156
  end
276
-
277
- it 'returns film objects with correct names' do
278
- subject.first.name.must_equal 'Gravity'
279
- subject.last.name.must_equal 'Don Jon'
280
- end
281
157
  end
282
158
 
283
159
  describe '#full_name' do
@@ -286,11 +162,6 @@ describe CineworldUk::Cinema do
286
162
  describe 'simple name (brighton)' do
287
163
  let(:cinema) { CineworldUk::Cinema.new('3', 'Brighton') }
288
164
 
289
- before do
290
- body = File.read( File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'cinemas', 'brighton.html') )
291
- stub_request(:get, 'http://www.cineworld.co.uk/cinemas/3/information').to_return( status: 200, body: body, headers: {} )
292
- end
293
-
294
165
  it 'returns the brand in the name' do
295
166
  subject.must_equal 'Cineworld Brighton'
296
167
  end
@@ -299,11 +170,6 @@ describe CineworldUk::Cinema do
299
170
  describe 'complex name (glasgow imax)' do
300
171
  let(:cinema) { CineworldUk::Cinema.new('88', 'Glasgow - IMAX at GSC') }
301
172
 
302
- before do
303
- body = File.read( File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'cinemas', 'glasgow-imax-at-gsc.html') )
304
- stub_request(:get, 'http://www.cineworld.co.uk/cinemas/88/information').to_return( status: 200, body: body, headers: {} )
305
- end
306
-
307
173
  it 'returns the brand in the name' do
308
174
  subject.must_equal 'Cineworld Glasgow: IMAX at GSC'
309
175
  end
@@ -317,12 +183,13 @@ describe CineworldUk::Cinema do
317
183
  let(:cinema) { CineworldUk::Cinema.new('3', 'Brighton') }
318
184
 
319
185
  before do
320
- body = File.read( File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'cinemas', 'brighton.html') )
321
- stub_request(:get, 'http://www.cineworld.co.uk/cinemas/3/information').to_return( status: 200, body: body, headers: {} )
186
+ website.expect(:information, information_html('brighton'), [3])
322
187
  end
323
188
 
324
189
  it 'returns the town/city' do
325
- subject.must_equal 'Brighton'
190
+ CineworldUk::Internal::Website.stub :new, website do
191
+ subject.must_equal 'Brighton'
192
+ end
326
193
  end
327
194
  end
328
195
 
@@ -330,51 +197,13 @@ describe CineworldUk::Cinema do
330
197
  let(:cinema) { CineworldUk::Cinema.new('4', 'Bristol') }
331
198
 
332
199
  before do
333
- body = File.read( File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'cinemas', 'bristol.html') )
334
- stub_request(:get, 'http://www.cineworld.co.uk/cinemas/4/information').to_return( status: 200, body: body, headers: {} )
200
+ website.expect(:information, information_html('bristol'), [4])
335
201
  end
336
202
 
337
203
  it 'returns the town/city' do
338
- subject.must_equal 'Bristol'
339
- end
340
- end
341
-
342
- describe '(bury st edmunds)' do
343
- let(:cinema) { CineworldUk::Cinema.new('6', 'Bury St. Edmunds') }
344
-
345
- before do
346
- body = File.read( File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'cinemas', 'bury-st-edmunds.html') )
347
- stub_request(:get, 'http://www.cineworld.co.uk/cinemas/6/information').to_return( status: 200, body: body, headers: {} )
348
- end
349
-
350
- it 'returns the town/city' do
351
- subject.must_equal 'Bury St. Edmunds'
352
- end
353
- end
354
-
355
- describe '(london chelsea)' do
356
- let(:cinema) { CineworldUk::Cinema.new('10', 'London - Chelsea') }
357
-
358
- before do
359
- body = File.read( File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'cinemas', 'chelsea.html') )
360
- stub_request(:get, 'http://www.cineworld.co.uk/cinemas/10/information').to_return( status: 200, body: body, headers: {} )
361
- end
362
-
363
- it 'returns the town/city' do
364
- subject.must_equal 'London'
365
- end
366
- end
367
-
368
- describe '(london o2)' do
369
- let(:cinema) { CineworldUk::Cinema.new('79', 'The O2, Grenwich') }
370
-
371
- before do
372
- body = File.read( File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'cinemas', 'the-o2-grenwich.html') )
373
- stub_request(:get, 'http://www.cineworld.co.uk/cinemas/79/information').to_return( status: 200, body: body, headers: {} )
374
- end
375
-
376
- it 'returns the town/city' do
377
- subject.must_equal 'London'
204
+ CineworldUk::Internal::Website.stub :new, website do
205
+ subject.must_equal 'Bristol'
206
+ end
378
207
  end
379
208
  end
380
209
  end
@@ -386,12 +215,13 @@ describe CineworldUk::Cinema do
386
215
  let(:cinema) { CineworldUk::Cinema.new('3', 'Brighton') }
387
216
 
388
217
  before do
389
- body = File.read( File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'cinemas', 'brighton.html') )
390
- stub_request(:get, 'http://www.cineworld.co.uk/cinemas/3/information').to_return( status: 200, body: body, headers: {} )
218
+ website.expect(:information, information_html('brighton'), [3])
391
219
  end
392
220
 
393
221
  it 'returns the post code' do
394
- subject.must_equal 'BN2 5UF'
222
+ CineworldUk::Internal::Website.stub :new, website do
223
+ subject.must_equal 'BN2 5UF'
224
+ end
395
225
  end
396
226
  end
397
227
  end
@@ -403,12 +233,13 @@ describe CineworldUk::Cinema do
403
233
  let(:cinema) { CineworldUk::Cinema.new('3', 'Brighton') }
404
234
 
405
235
  before do
406
- body = File.read( File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'cinemas', 'brighton.html') )
407
- stub_request(:get, 'http://www.cineworld.co.uk/cinemas/3/information').to_return( status: 200, body: body, headers: {} )
236
+ website.expect(:information, information_html('brighton'), [3])
408
237
  end
409
238
 
410
239
  it 'returns the county' do
411
- subject.must_equal 'East Sussex'
240
+ CineworldUk::Internal::Website.stub :new, website do
241
+ subject.must_equal 'East Sussex'
242
+ end
412
243
  end
413
244
  end
414
245
 
@@ -416,72 +247,25 @@ describe CineworldUk::Cinema do
416
247
  let(:cinema) { CineworldUk::Cinema.new('4', 'Bristol') }
417
248
 
418
249
  before do
419
- body = File.read( File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'cinemas', 'bristol.html') )
420
- stub_request(:get, 'http://www.cineworld.co.uk/cinemas/4/information').to_return( status: 200, body: body, headers: {} )
250
+ website.expect(:information, information_html('bristol'), [4])
421
251
  end
422
252
 
423
253
  it 'returns nil' do
424
- subject.must_be_nil
425
- end
426
- end
427
-
428
- describe '(bury st edmunds)' do
429
- let(:cinema) { CineworldUk::Cinema.new('6', 'Bury St. Edmunds') }
430
-
431
- before do
432
- body = File.read( File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'cinemas', 'bury-st-edmunds.html') )
433
- stub_request(:get, 'http://www.cineworld.co.uk/cinemas/6/information').to_return( status: 200, body: body, headers: {} )
434
- end
435
-
436
- it 'returns nil' do
437
- subject.must_be_nil
438
- end
439
- end
440
-
441
- describe '(london o2)' do
442
- let(:cinema) { CineworldUk::Cinema.new('79', 'The O2, Grenwich') }
443
-
444
- before do
445
- body = File.read( File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'cinemas', 'the-o2-grenwich.html') )
446
- stub_request(:get, 'http://www.cineworld.co.uk/cinemas/79/information').to_return( status: 200, body: body, headers: {} )
447
- end
448
-
449
- it 'returns nil' do
450
- subject.must_be_nil
254
+ CineworldUk::Internal::Website.stub :new, website do
255
+ subject.must_be_nil
256
+ end
451
257
  end
452
258
  end
453
-
454
259
  end
455
260
 
456
261
  describe '#screenings' do
457
- let(:cinema) { CineworldUk::Cinema.new('3', 'Brighton') }
458
- subject { cinema.screenings }
459
-
460
- before do
461
- body = File.read( File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'whatson', 'brighton.html') )
462
- stub_request(:get, 'http://www.cineworld.co.uk/whatson?cinema=3').to_return( status: 200, body: body, headers: {} )
463
- end
262
+ subject { CineworldUk::Cinema.new('3', 'Brighton').screenings }
464
263
 
465
- it 'returns an array of screenings' do
466
- subject.must_be_instance_of(Array)
467
- subject.each do |item|
468
- item.must_be_instance_of(CineworldUk::Screening)
264
+ it 'calls out to Screening object' do
265
+ CineworldUk::Screening.stub :at, [:screening] do
266
+ subject.must_equal([:screening])
469
267
  end
470
268
  end
471
-
472
- it 'returns screening objects with correct film names' do
473
- subject.first.film_name.must_equal 'Gravity'
474
- subject.last.film_name.must_equal 'Don Jon'
475
- end
476
-
477
- it 'returns screening objects with correct cinema name' do
478
- subject.each { |screening| screening.cinema_name.must_equal 'Brighton' }
479
- end
480
-
481
- it 'returns screening objects with correct UTC times' do
482
- subject.first.when.must_equal Time.utc(2013, 11, 13, 12, 0, 0)
483
- subject.last.when.must_equal Time.utc(2013, 11, 21, 21, 30, 0)
484
- end
485
269
  end
486
270
 
487
271
  describe '#street_address' do
@@ -491,13 +275,32 @@ describe CineworldUk::Cinema do
491
275
  let(:cinema) { CineworldUk::Cinema.new('3', 'Brighton') }
492
276
 
493
277
  before do
494
- body = File.read( File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'cinemas', 'brighton.html') )
495
- stub_request(:get, 'http://www.cineworld.co.uk/cinemas/3/information').to_return( status: 200, body: body, headers: {} )
278
+ website.expect(:information, information_html('brighton'), [3])
496
279
  end
497
280
 
498
281
  it 'returns the street address' do
499
- subject.must_equal 'Brighton Marina'
282
+ CineworldUk::Internal::Website.stub :new, website do
283
+ subject.must_equal 'Brighton Marina'
284
+ end
500
285
  end
501
286
  end
502
287
  end
288
+
289
+ private
290
+
291
+ def read_file(filepath)
292
+ File.read(File.expand_path(filepath, __FILE__))
293
+ end
294
+
295
+ def cinemas_html
296
+ read_file('../../../fixtures/cinemas.html')
297
+ end
298
+
299
+ def information_html(filename)
300
+ read_file("../../../fixtures/information/#{filename}.html")
301
+ end
302
+
303
+ def parse(html)
304
+ Nokogiri::HTML(html)
305
+ end
503
306
  end
@@ -11,6 +11,43 @@ describe CineworldUk::Film do
11
11
  end
12
12
  end
13
13
 
14
+ describe '.at(cinema_id)' do
15
+ let(:website) { Minitest::Mock.new }
16
+
17
+ subject { CineworldUk::Film.at(3) }
18
+
19
+ before do
20
+ website.expect(:whatson, whatson_html('brighton'), [3])
21
+ end
22
+
23
+ it 'returns an array of films' do
24
+ CineworldUk::Internal::Website.stub :new, website do
25
+ subject.must_be_instance_of(Array)
26
+ subject.each do |film|
27
+ film.must_be_instance_of(CineworldUk::Film)
28
+ end
29
+ end
30
+ end
31
+
32
+ it 'returns a decent number of films' do
33
+ CineworldUk::Internal::Website.stub :new, website do
34
+ subject.count.must_be :>, 15
35
+ end
36
+ end
37
+
38
+ it 'returns uniquely named films' do
39
+ CineworldUk::Internal::Website.stub :new, website do
40
+ subject.each_with_index do |item, index|
41
+ subject.each_with_index do |jtem, i|
42
+ next if index == i
43
+ item.name.wont_equal jtem.name
44
+ item.wont_equal jtem
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+
14
51
  describe 'Comparable' do
15
52
  it 'includes comparable methods' do
16
53
  film = CineworldUk::Film.new 'AAAA'
@@ -47,7 +84,7 @@ describe CineworldUk::Film do
47
84
  it 'retuns only one' do
48
85
  result = [film, otherfilm].uniq
49
86
  result.count.must_equal 1
50
- result.must_equal [ CineworldUk::Film.new('AAAA') ]
87
+ result.must_equal [CineworldUk::Film.new('AAAA')]
51
88
  end
52
89
  end
53
90
  end
@@ -60,7 +97,7 @@ describe CineworldUk::Film do
60
97
  let(:otherfilm) { CineworldUk::Film.new 'BBBB' }
61
98
 
62
99
  it 'retuns -1' do
63
- subject.must_equal -1
100
+ subject.must_equal(-1)
64
101
  end
65
102
  end
66
103
 
@@ -92,4 +129,14 @@ describe CineworldUk::Film do
92
129
  end
93
130
  end
94
131
  end
132
+
133
+ private
134
+
135
+ def read_file(filepath)
136
+ File.read(File.expand_path(filepath, __FILE__))
137
+ end
138
+
139
+ def whatson_html(filename)
140
+ read_file("../../../fixtures/whatson/#{filename}.html")
141
+ end
95
142
  end