On Aug 20, 3:02 pm, Mike Sassak <[email protected]> wrote: > On Thu, Aug 20, 2009 at 3:00 PM, Ed Ruder <[email protected]> wrote: > > All, > > > In a Rails helper spec, how do I stub or mock the 'link_to' method? > > When i step into link_to, self.class is > > > Spec::Rails::Example::HelperExampleGroup::Subclass_1::Subclass_5::Subclass_ > > 1. > > > What I'm trying to do is stub link_to and check that its parameters > > are correct--i.e., that a helper method is properly constructing the > > parameters to link_to. The work-around (and what seems to me to be a > > more awkward approach) is to grep the output of the helper method for > > a link with a proper href property. > > Hi Ed, > > Verifying the output of the helper method isn't a work around at all. > Rather, it sounds like exactly what you should be doing in this case. Think > of the helper method as a black box--you only care what comes out, not, > necessarily, how it got there. Verifying output in this way rather than the > implementation makes your specs more resilient in the face of changes, (what > would happen, for example, if the calling semantics of link_to changed in a > newer versions of Rails?), and is one of the central tenets of test/behavior > driven development. RSpec already has lots of methods to verify HTML, too. > See the Expectations section > athttp://rspec.info/rails/writing/views.htmlformore details. > > Mike
Mike, Sounds OK. Thanks. Ed _______________________________________________ rspec-users mailing list [email protected] http://rubyforge.org/mailman/listinfo/rspec-users
