Browse files

Include ApplicationHelper in helper object in helper specs.

- Closes #276.
  • Loading branch information...
1 parent 6717927 commit aa1b9eb83bcec0f5ec0a1b0caf165cd0ba84f310 @dchelimsky dchelimsky committed Dec 20, 2010
View
3 History.md
@@ -4,6 +4,9 @@
[full changelog](http://github.com/rspec/rspec-rails/compare/v2.3.1...master)
+* Enhancements
+ * include ApplicationHelper in helper object in helper specs
+
* Bug fixes
* restore global config.render_views so you only need to say it once
View
33 features/helper_specs/helper_spec.feature
@@ -51,3 +51,36 @@ Feature: helper spec
"""
When I run "rspec spec/helpers/application_helper_spec.rb"
Then the output should contain "1 example, 0 failures"
+
+ Scenario: application helper is included in helper object
+ Given a file named "spec/helpers/widgets_helper_spec.rb" with:
+ """
+ require "spec_helper"
+
+ describe WidgetsHelper do
+ describe "#page_title" do
+ it "includes the app name" do
+ assign(:title, "This Page")
+ helper.page_title.should eq("The App: This Page")
+ end
+ end
+ end
+ """
+ And a file named "app/helpers/application_helper.rb" with:
+ """
+ module ApplicationHelper
+ def app_name
+ "The App"
+ end
+ end
+ """
+ And a file named "app/helpers/widgets_helper.rb" with:
+ """
+ module WidgetsHelper
+ def page_title
+ "#{app_name}: #{@title}"
+ end
+ end
+ """
+ When I run "rspec spec/helpers/widgets_helper_spec.rb"
+ Then the output should contain "1 example, 0 failures"
View
5 lib/rspec/rails/example/helper_example_group.rb
@@ -49,7 +49,10 @@ module InstanceMethods
# Returns an instance of ActionView::Base with the helper being specified
# mixed in, along with any of the built-in rails helpers.
def helper
- _view.tap {|v| v.assign(view_assigns)}
+ _view.tap do |v|
+ v.extend(ApplicationHelper) if defined?(ApplicationHelper)
+ v.assign(view_assigns)
+ end
end
private
View
18 spec/rspec/rails/example/helper_example_group_spec.rb
@@ -30,6 +30,24 @@ module ::FoosHelper; end
helper_spec.stub(:_view) { av_tc_b_view }
helper_spec.helper.should eq(av_tc_b_view)
end
+
+ before do
+ Object.const_set(:ApplicationHelper, Module.new)
+ end
+
+ after do
+ Object.__send__(:remove_const, :ApplicationHelper)
+ end
+
+ it "includes ApplicationHelper" do
+ group = RSpec::Core::ExampleGroup.describe do
+ include HelperExampleGroup
+ def _view
+ ActionView::Base.new
+ end
+ end
+ group.new.helper.should be_kind_of(ApplicationHelper)
+ end
end
end

0 comments on commit aa1b9eb

Please sign in to comment.