Class: Spec::Rails::Example::HelperExampleGroup
- Inherits:
-
FunctionalExampleGroup
- Object
- ActionController::TestCase
- FunctionalExampleGroup
- Spec::Rails::Example::HelperExampleGroup
- Defined in:
- lib/vendor/plugins/rspec-rails/lib/spec/rails/example/helper_example_group.rb
Overview
Helper Specs live in $RAILS_ROOT/spec/helpers/.
Helper Specs use Spec::Rails::Example::HelperExampleGroup, which allows you to include your Helper directly in the context and write specs directly against its methods.
HelperExampleGroup also includes the standard lot of ActionView::Helpers in case your helpers rely on any of those.
Example
module ThingHelper
def number_of_things
Thing.count
end
end
describe "ThingHelper example_group" do
include ThingHelper
it "should tell you the number of things" do
Thing.should_receive(:count).and_return(37)
number_of_things.should == 37
end
end
Defined Under Namespace
Classes: HelperObject
Instance Attribute Summary collapse
-
#output_buffer ⇒ Object
Returns the value of attribute output_buffer.
Attributes inherited from FunctionalExampleGroup
Class Method Summary collapse
- .helper ⇒ Object
-
.helper_name(name = nil) ⇒ Object
The helper name.…
Instance Method Summary collapse
- #eval_erb(text) ⇒ Object
- #flash ⇒ Object
-
#helper ⇒ Object
Returns an instance of ActionView::Base with the helper being spec’d included.
- #orig_assigns ⇒ Object
-
#protect_against_forgery? ⇒ Boolean
TODO: BT - Helper Examples should proxy method_missing to a Rails View instance.
Methods inherited from FunctionalExampleGroup
#assigns, #cookies, #params, #session, #setup
Methods inherited from ActionController::TestCase
Methods included from RoutingHelpers
Instance Attribute Details
#output_buffer ⇒ Object
Returns the value of attribute output_buffer.
34 35 36 |
# File 'lib/vendor/plugins/rspec-rails/lib/spec/rails/example/helper_example_group.rb', line 34 def output_buffer @output_buffer end |
Class Method Details
.helper ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/vendor/plugins/rspec-rails/lib/spec/rails/example/helper_example_group.rb', line 58 def helper @helper_object ||= returning HelperObject.new do |helper_object| if @helper_being_described.nil? if described_type.class == Module helper_object.extend described_type end else helper_object.extend @helper_being_described end end end |
.helper_name(name = nil) ⇒ Object
The helper name.…
53 54 55 56 |
# File 'lib/vendor/plugins/rspec-rails/lib/spec/rails/example/helper_example_group.rb', line 53 def helper_name(name=nil) @helper_being_described = "#{name}_helper".camelize.constantize send :include, @helper_being_described end |
Instance Method Details
#eval_erb(text) ⇒ Object
125 126 127 128 129 130 131 132 133 134 |
# File 'lib/vendor/plugins/rspec-rails/lib/spec/rails/example/helper_example_group.rb', line 125 def eval_erb(text) erb_args = [text] if helper.respond_to?(:output_buffer) erb_args += [nil, nil, '@output_buffer'] end helper.instance_eval do ERB.new(*erb_args).result(binding) end end |
#flash ⇒ Object
121 122 123 |
# File 'lib/vendor/plugins/rspec-rails/lib/spec/rails/example/helper_example_group.rb', line 121 def flash @flash end |
#helper ⇒ Object
Returns an instance of ActionView::Base with the helper being spec’d included.
Example
describe PersonHelper do
it "should write a link to person with the name" do
assigns[:person] = mock_model(Person, :full_name => "Full Name", :id => 37, :new_record? => false)
helper.link_to_person.should == %{<a href="/people/37">Full Name</a>}
end
end
module PersonHelper
def link_to_person
link_to person.full_name, url_for(person)
end
end
89 90 91 |
# File 'lib/vendor/plugins/rspec-rails/lib/spec/rails/example/helper_example_group.rb', line 89 def helper self.class.helper end |
#orig_assigns ⇒ Object
93 94 95 |
# File 'lib/vendor/plugins/rspec-rails/lib/spec/rails/example/helper_example_group.rb', line 93 def orig_assigns helper.assigns end |
#protect_against_forgery? ⇒ Boolean
TODO: BT - Helper Examples should proxy method_missing to a Rails View instance. When that is done, remove this method
138 139 140 |
# File 'lib/vendor/plugins/rspec-rails/lib/spec/rails/example/helper_example_group.rb', line 138 def protect_against_forgery? false end |