[rspec-users] How-to spec this helper method?...

David Chelimsky dchelimsky at gmail.com
Mon Dec 24 10:24:59 EST 2007


On Dec 24, 2007 7:48 AM, Bart Zonneveld <loop at superinfinite.com> wrote:
>
>
> On 24 dec 2007, at 05:09, David Chelimsky wrote:
>
> > On Dec 20, 2007 4:31 AM, Bart Zonneveld <loop at superinfinite.com>
> > wrote:
> >> Hey gang,
> >>
> >> I have this dead-simple method defined in a helper:
> >>
> >>   def add_category_link(name)
> >>     link_to_function name do |page|
> >>       page.insert_html :bottom, :categories, :partial =>
> >> 'category', :object => Category.new
> >>     end
> >>   end
> >>
> >> Where, and mostly how, would I spec this? I haven't been able to find
> >> how to stub the rjs in a helper spec, so I'd appreciate any pointers
> >> whatsoever..
> >
> > If you can spec it in a template using rjs, you can do it in a helper:
> >
> > describe FooHelper do
> >  it "should build a category link" do
> >    add_category_link(:foo).should have_rjs(...)
> >  end
> > end
>
> Thanks! However, I am getting an error about 'nil.render' now, with
> this backtrace:

Just for fun - try putting it in a view specs instead and include the helper:

describe "FooHelper", :type => :view do
  include FooHelper
  # etc
end

It might be that view specs have services you need for this example
that don't exist in helper specs. If it works, then you can use that
as a workaround for now and we know where the deficiency lies. If so,
please submit a ticket at http://rspec.lighthouseapp.com/.

Cheers,
David

>
> You have a nil object when you didn't expect it!
> The error occurred while evaluating nil.render
> /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.0.1/lib/action_view/
> helpers/prototype_helper.rb:956:in `render'
> /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.0.1/lib/action_view/
> helpers/prototype_helper.rb:727:in `insert_html'
> /Users/bartz/Documents/workspace/blog/app/helpers/admin/
> admin_helper.rb:34:in `__instance_exec0'
> /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/
> active_support/core_ext/object/extending.rb:52:in `send'
> /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/
> active_support/core_ext/object/extending.rb:52:in `instance_exec'
> /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.0.1/lib/action_view/
> helpers/prototype_helper.rb:581:in `initialize'
> /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.0.1/lib/action_view/
> helpers/prototype_helper.rb:992:in `new'
> /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.0.1/lib/action_view/
> helpers/prototype_helper.rb:992:in `update_page'
> /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.0.1/lib/action_view/
> helpers/javascript_helper.rb:87:in `link_to_function'
>
> No idea how to fix this :(...
>
> thanks in advance, and happy Christmas and all!
>
> bartz
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list