Class Spec::Rails::Example::HelperExampleGroup
In: vendor/plugins/rspec-rails/lib/spec/rails/example/helper_example_group.rb
Parent: Spec::Rails::Example::FunctionalExampleGroup

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

  class 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

Methods

Classes and Modules

Class Spec::Rails::Example::HelperExampleGroup::HelperObject

Public Class methods

[Source]

    # File vendor/plugins/rspec-rails/lib/spec/rails/example/helper_example_group.rb, line 65
65:           def helper
66:             @helper_object ||= returning HelperObject.new do |helper_object|
67:               if @helper_being_described.nil?
68:                 if described_type.class == Module
69:                   helper_object.extend described_type
70:                 end
71:               else
72:                 helper_object.extend @helper_being_described
73:               end
74:             end
75:           end

The helper name.…

[Source]

    # File vendor/plugins/rspec-rails/lib/spec/rails/example/helper_example_group.rb, line 60
60:           def helper_name(name=nil)
61:             @helper_being_described = "#{name}_helper".camelize.constantize
62:             send :include, @helper_being_described
63:           end

Public Instance methods

[Source]

     # File vendor/plugins/rspec-rails/lib/spec/rails/example/helper_example_group.rb, line 130
130:         def eval_erb(text)
131:           erb_args = [text]
132:           if helper.respond_to?(:output_buffer)
133:             erb_args += [nil, nil, '@output_buffer']
134:           end
135:           
136:           helper.instance_eval do
137:             ERB.new(*erb_args).result(binding)
138:           end
139:         end

[Source]

     # File vendor/plugins/rspec-rails/lib/spec/rails/example/helper_example_group.rb, line 126
126:         def flash
127:           @flash
128:         end

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

[Source]

    # File vendor/plugins/rspec-rails/lib/spec/rails/example/helper_example_group.rb, line 96
96:         def helper
97:           self.class.helper
98:         end

TODO: BT - Helper Examples should proxy method_missing to a Rails View instance. When that is done, remove this method

[Source]

     # File vendor/plugins/rspec-rails/lib/spec/rails/example/helper_example_group.rb, line 143
143:         def protect_against_forgery?
144:           false
145:         end

Protected Instance methods

[Source]

     # File vendor/plugins/rspec-rails/lib/spec/rails/example/helper_example_group.rb, line 150
150:         def _assigns_hash_proxy
151:           @_assigns_hash_proxy ||= AssignsHashProxy.new helper
152:         end

[Validate]