class Spec::Rails::Example::HelperExampleGroup
end
end
number_of_things.should == 37
Thing.should_receive(:count).and_return(37)
it “should tell you the number of things” do
include ThingHelper
describe “ThingHelper example_group” do
end
end
Thing.count
def number_of_things
class ThingHelper
== Example
helpers rely on any of those.
HelperExampleGroup also includes the standard lot of ActionView::Helpers in case your
against its methods.
include your Helper directly in the context and write specs directly
Helper Specs use Spec::Rails::Example::HelperExampleGroup, which allows you to
Helper Specs live in $RAILS_ROOT/spec/helpers/.
def _assigns_hash_proxy
def _assigns_hash_proxy @_assigns_hash_proxy ||= AssignsHashProxy.new self do helper end end
def eval_erb(text)
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
def flash
def flash @flash end
def helper
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
def helper
end
end
link_to person.full_name, url_for(person)
def link_to_person
module PersonHelper
end
end
helper.link_to_person.should == %{Full Name}
assigns[:person] = mock_model(Person, :full_name => "Full Name", :id => 37, :new_record? => false)
it "should write a link to person with the name" do
describe PersonHelper do
== Example
included.
Returns an instance of ActionView::Base with the helper being spec'd
def helper self.class.helper end
def helper_name(name=nil)
def helper_name(name=nil) @helper_being_described = "#{name}_helper".camelize.constantize send :include, @helper_being_described end
def orig_assigns
def orig_assigns helper.assigns end
def protect_against_forgery?
TODO: BT - Helper Examples should proxy method_missing to a Rails View instance.
def protect_against_forgery? false end