Created
July 15, 2010 09:28
-
-
Save wincent/476715 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/features/view_specs/view_spec.feature b/features/view_specs/view_spec.feature | |
index e85c306..7cce24e 100644 | |
--- a/features/view_specs/view_spec.feature | |
+++ b/features/view_specs/view_spec.feature | |
@@ -152,3 +152,34 @@ Feature: view spec | |
""" | |
When I run "rspec spec/views" | |
Then the output should contain "1 example, 0 failures" | |
+ | |
+ Scenario: spec with view that accesses helper_method helpers | |
+ Given a file named "app/controllers/application_controller.rb" with: | |
+ """ | |
+ class ApplicationController < ActionController::Base | |
+ protected | |
+ def admin? | |
+ true | |
+ end | |
+ helper_method :admin? | |
+ end | |
+ """ | |
+ And a file named "app/views/gadgets/index.html.erb" with: | |
+ """ | |
+ <%- if admin? %> | |
+ <h1>Secret admin area</h1> | |
+ <%- end %> | |
+ """ | |
+ And a file named "spec/views/gadgets/index.html.erb_spec.rb" with: | |
+ """ | |
+ require 'spec_helper' | |
+ | |
+ describe 'gadgets/index.html.erb' do | |
+ it 'checks for admin access' do | |
+ render | |
+ rendered.should contain('Secret admin area') | |
+ end | |
+ end | |
+ """ | |
+ When I run "rspec spec/views" | |
+ Then the output should contain "1 example, 0 failures" | |
diff --git a/lib/rspec/rails/example/view_example_group.rb b/lib/rspec/rails/example/view_example_group.rb | |
index 40e371a..03af10d 100644 | |
--- a/lib/rspec/rails/example/view_example_group.rb | |
+++ b/lib/rspec/rails/example/view_example_group.rb | |
@@ -102,7 +102,6 @@ module RSpec::Rails | |
view | |
end | |
- | |
# Deprecated. Use +rendered+ instead. | |
def response | |
RSpec.deprecate("response", "rendered") | |
@@ -118,6 +117,13 @@ module RSpec::Rails | |
def _controller_path | |
_default_file_to_render.split("/")[0..-2].join("/") | |
end | |
+ | |
+ def _include_controller_helpers | |
+ metaclass = class << view; self; end | |
+ unless metaclass.included_modules.include?(controller._helpers) | |
+ metaclass.__send__(:include, controller._helpers) | |
+ end | |
+ end | |
end | |
included do | |
@@ -125,6 +131,7 @@ module RSpec::Rails | |
helper *_default_helpers | |
before do | |
+ _include_controller_helpers | |
controller.controller_path = _controller_path | |
# this won't be necessary if/when | |
# https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/4903 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment