Skip to content

Commit

Permalink
Provide a better example of how to stub a helper method in a view spec
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alanshields committed Aug 3, 2011
1 parent 95dac95 commit 6878df5
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions features/view_specs/view_spec.feature
Expand Up @@ -134,7 +134,7 @@ Feature: view spec
When I run `rspec spec/views`
Then the examples should all pass

Scenario: spec with view that accesses helper_method helpers
Scenario: passing view spec that stubs a helper method
Given a file named "app/views/secrets/index.html.erb" with:
"""
<%- if admin? %>
Expand All @@ -147,13 +147,7 @@ Feature: view spec
describe 'secrets/index.html.erb' do
before do
controller.singleton_class.class_eval do
protected
def admin?
true
end
helper_method :admin?
end
view.stub(:admin?).and_return(true)
end
it 'checks for admin access' do
Expand Down

0 comments on commit 6878df5

Please sign in to comment.