@@ -280,33 +280,65 @@ def _view; end
280
280
281
281
describe '#stub_template' do
282
282
let ( :view_spec_group ) do
283
- Class . new do
284
- include ViewExampleGroup ::ExampleMethods
285
- def _view
286
- @_view ||= Struct . new ( :view_paths ) . new ( ActionView ::PathSet . new ( [ 'some-path' ] ) )
287
- end
283
+ RSpec . describe "a view spec" do
284
+ include ::RSpec ::Rails ::ViewExampleGroup
288
285
end
289
286
end
290
287
291
288
it 'prepends an ActionView::FixtureResolver to the view path' do
292
- view_spec = view_spec_group . new
293
- view_spec . stub_template ( 'some_path/some_template' => 'stubbed-contents' )
289
+ result = :not_loaded
294
290
295
- result = view_spec . view . view_paths . first
291
+ view_spec_group . specify do
292
+ stub_template ( 'some_path/some_template' => 'stubbed-contents' )
293
+ result = view . view_paths . first
294
+ end
295
+ view_spec_group . run
296
296
297
297
expect ( result ) . to be_instance_of ( ActionView ::FixtureResolver )
298
298
data = result . respond_to? ( :data ) ? result . data : result . hash
299
299
expect ( data ) . to eq ( 'some_path/some_template' => 'stubbed-contents' )
300
300
end
301
301
302
+ it 'caches FixtureResolver instances between examples' do
303
+ example_one_view_paths = :not_set
304
+ example_two_view_paths = :not_set
305
+
306
+ view_spec_group . specify do
307
+ stub_template ( 'some_path/some_template' => 'stubbed-contents' )
308
+ example_one_view_paths = view . view_paths
309
+ end
310
+ view_spec_group . specify do
311
+ stub_template ( 'some_path/some_template' => 'stubbed-contents' )
312
+ example_two_view_paths = view . view_paths
313
+ end
314
+ view_spec_group . run
315
+
316
+ expect ( example_one_view_paths . first ) . to eq ( example_two_view_paths . first )
317
+ end
318
+
302
319
it 'caches FixtureResolver instances between example groups' do
303
- view_spec_one = view_spec_group . new
304
- view_spec_two = view_spec_group . new
320
+ example_one_view_paths = :not_set
321
+ example_two_view_paths = :not_set
305
322
306
- view_spec_one . stub_template ( 'some_path/some_template' => 'stubbed-contents' )
307
- view_spec_two . stub_template ( 'some_path/some_template' => 'stubbed-contents' )
323
+ RSpec . describe "a view spec" do
324
+ include ::RSpec ::Rails ::ViewExampleGroup
325
+
326
+ specify do
327
+ stub_template ( 'some_path/some_template' => 'stubbed-contents' )
328
+ example_one_view_paths = view . view_paths
329
+ end
330
+ end . run
331
+
332
+ RSpec . describe "another view spec" do
333
+ include ::RSpec ::Rails ::ViewExampleGroup
334
+
335
+ specify do
336
+ stub_template ( 'some_path/some_template' => 'stubbed-contents' )
337
+ example_two_view_paths = view . view_paths
338
+ end
339
+ end . run
308
340
309
- expect ( view_spec_one . view . view_paths . first ) . to eq ( view_spec_two . view . view_paths . first )
341
+ expect ( example_one_view_paths . first ) . to eq ( example_two_view_paths . first )
310
342
end
311
343
end
312
344
end
0 commit comments