[rspec-users] [rspec] [rails] Specing a form builder

Chris Flipse cflipse at gmail.com
Thu Feb 5 11:05:52 EST 2009

I'm trying to set up and run a new form builder under rails, which lives
under the helpers directory, but isn't really a helper.  (Not a module, so
doesn't mix in well)

Short of dropping down into a view spec, how do I set up to actually spec
the form builder?

describe RandomFormBuilder do
  attr_reader  :builder
  before do
    @object = mock_model(Foo)
    @builder = RandomFormBuilder.new(:foo, @object, #template#, {}, nil)

  describe "#text_field" do
    it "should have a label" do
       @builder.text_field(:foo).should have_tag("label", "Foo")

class RandomFormBuilder < ActionView::Helpers::FormBuilder
  def  text_field(method, *args)
    super(method, *args)

That's sort of what I've got at the moment.  #template# supposed to be an
object with access to all the normal helpers, I _think_.
using helper in that location gives me a NoMethodError.

using self in that location ends up with the helper trying to delegate
methods to Spec::Rails::Example::RailsExampleGroup::Subclass ....

has anybody figured out what hoops this needs?

// anything worth taking seriously is worth making fun of
// http://blog.devcaffeine.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20090205/d529d0cc/attachment.html>

More information about the rspec-users mailing list