Skip to content

Commit 6878df5

Browse files
committed
Provide a better example of how to stub a helper method in a view spec
When I upgraded to Rails 3.0.9 I ran into an issue where controller.singleton_class.class_eval was leaving behind cruft for other tests to run into. We exploit the fact that helper methods are imported into the view class to stub those helpers.
1 parent 95dac95 commit 6878df5

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

features/view_specs/view_spec.feature

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ Feature: view spec
134134
When I run `rspec spec/views`
135135
Then the examples should all pass
136136

137-
Scenario: spec with view that accesses helper_method helpers
137+
Scenario: passing view spec that stubs a helper method
138138
Given a file named "app/views/secrets/index.html.erb" with:
139139
"""
140140
<%- if admin? %>
@@ -147,13 +147,7 @@ Feature: view spec
147147
148148
describe 'secrets/index.html.erb' do
149149
before do
150-
controller.singleton_class.class_eval do
151-
protected
152-
def admin?
153-
true
154-
end
155-
helper_method :admin?
156-
end
150+
view.stub(:admin?).and_return(true)
157151
end
158152
159153
it 'checks for admin access' do

0 commit comments

Comments
 (0)