Skip to content

Commit b55570a

Browse files
committed
Merge pull request #873 from rspec/verify_views_are_accessible_to_hooks_3x
Merge #833 into master
2 parents 57c8d42 + 2dd9640 commit b55570a

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

lib/rspec/rails/adapters.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ module ClassMethods
105105
# hooks.
106106
def setup(*methods)
107107
methods.each do |method|
108-
if method.to_s =~ /^setup_(fixtures|controller_request_and_response)$/
108+
if method.to_s =~ /^setup_(with_controller|fixtures|controller_request_and_response)$/
109109
prepend_before { __send__ method }
110110
else
111111
before { __send__ method }

spec/rspec/rails/example/view_example_group_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,21 @@ def controller
194194
allow(view_spec).to receive(:_view) { view }
195195
expect(view_spec.view).to eq(view)
196196
end
197+
198+
it 'is accessible to hooks' do
199+
with_isolated_config do
200+
run_count = 0
201+
RSpec.configuration.before(:each, :type => :view) do
202+
allow(view).to receive(:a_stubbed_helper) { :value }
203+
run_count += 1
204+
end
205+
group = RSpec::Core::ExampleGroup.describe 'a view', :type => :view do
206+
specify { true }
207+
end
208+
group.run NullObject.new
209+
expect(run_count).to eq 1
210+
end
211+
end
197212
end
198213

199214
describe "#template" do

spec/support/helpers.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,19 @@ def metadata_with(additional_metadata)
1616
m
1717
end
1818

19+
def with_isolated_config
20+
original_config = RSpec.configuration
21+
RSpec.configuration = RSpec::Core::Configuration.new
22+
RSpec.configure do |c|
23+
c.include RSpec::Rails::FixtureSupport
24+
c.add_setting :use_transactional_fixtures, :alias_with => :use_transactional_examples
25+
c.add_setting :use_instantiated_fixtures
26+
c.add_setting :global_fixtures
27+
c.add_setting :fixture_path
28+
end
29+
yield
30+
RSpec.configuration = original_config
31+
end
32+
1933
RSpec.configure {|c| c.include self}
2034
end

0 commit comments

Comments
 (0)