[rspec-users] Test HTML output from Rails helper

Zach Dennis zach.dennis at gmail.com
Sat Oct 18 12:18:36 EDT 2008


On Sat, Oct 18, 2008 at 11:34 AM, Nick Hoffman <nick at deadorange.com> wrote:
> On 2008-10-18, at 09:16, Pat Maddox wrote:
>>
>> Scott Taylor <mailing_lists at railsnewbie.com> writes:
>>>
>>> You'd be able to write a spec like the following:
>>>
>>> it "should link with the correct name" do
>>>  helper.should_receive(:link_to).with("foo", {:controller =>  "foo",
>>> :action => "foo"})
>>>  helper.my_method("foo")
>>> end
>>
>> I don't like this, I don't think you're testing anything here.
>>
>> Pat
>
> Hi Pat. I'm interested to hear how you'd spec that helper method, because
> some of specs are similar to what Scott proposed, and I'm always looking to
> improve them.


I'm pretty sure Pat is simply suggesting:

  it "should link with the correct name" do
     helper.my_method("foo").should have_tag("a[href=?]", the_path, "foo")
  end

If my_method returns a string then have_tag will work. If my_method
returns an object that responds to "body" then it will also work (this
is how response.should have_tag('...') works as well,

-- 
Zach Dennis
http://www.continuousthinking.com
http://www.mutuallyhuman.com


More information about the rspec-users mailing list