Helpers

Helper Examples live in $RAILS_ROOT/spec/helpers/.

Writing specs for your helpers is a snap. Just tell the Example Group the name of the helper …

describe RegistrationHelper do
  ...
end

... and the Example Group will expose an object that includes the helper.

Conveniences

assigns

Use assigns[:key] to set instance variables to be used in the view that includes the helper. See example below.

Example Helper Spec

require File.dirname(__FILE__) + '/../spec_helper'

describe PeopleHelper do
  it "should say hello" do
    helper.say_hello.should == "Hello"
  end

  it "should provide person address text field tag" do
    assigns[:person] = Person.new(:address => "The moon")
    helper.person_address_text_field.should == "<input id=\"person_address\" name=\"person[address]\" size=\"30\" type=\"text\" value=\"The moon\" />"
  end
end