rspec-rails: View helpers not available in view specs
Just noticed that view helpers aren’t automatically included in views like they were in RSpec 1, so you need to include them explicitly in all your view specs:
before do
view.extend ApplicationHelper
view.extend FooHelper
end
Is this intentional or still on the “to do” list?
Cheers, Wincent
About this issue
- Original URL
- State: closed
- Created 14 years ago
- Comments: 30 (22 by maintainers)
Commits related to this issue
- Make view helpers available in view specs This maintains the behavior established in RSpec 1. Closes #119. — committed to jamesottaway/rspec-rails by wincent 14 years ago
- Include helper methods defined in controllers in the view object in ViewExampleGroup - based on gist from Wincent Colaiuta <win@wincent.com> - Closes #119. — committed to jamesottaway/rspec-rails by dchelimsky 14 years ago
OK - looks like this is an integration problem. RSpec is asking the controller for it’s helpers and adding them to the view: https://github.com/rspec/rspec-rails/blob/master/lib/rspec/rails/example/view_example_group.rb#L127-130
but the controller is a test controller, not any controller in your app: https://github.com/rails/rails/blob/master/actionpack/lib/action_view/test_case.rb#L100
We need a way to declare the controllers we want to grab helper methods from. In the short term you can do something like this (I think - untested - try it):
I’d consider adding
add_controller_helpers(or similar) to rspec-rails, but I think this really belongs in Rails proper. Either way, there is no reliable way for RSpec or Rails to infer which controller to use all of the time, so it’s probably best to leave that to the user.Thoughts?