On Sun, May 2, 2010 at 1:48 AM, Patrick J. Collins <[email protected]> wrote: > I have something like: > > class Foo > > def initialize(template) > �...@template = template > end > > def link > link_to "foo", foo_path > end > > def method_missing(*args, &block) > �[email protected](*args, &block) > end > end > > ... > before(:all) do > �...@foo = Foo.new(self) > end
Generally speaking, before(:each) is a better choice than before(:all). Each example gets run in its own instance, and using before(:all) risks leaking state from example to example. The pattern that you're implementing here is called the Self-Shunt Pattern, in which the example itself acts like a player in the code being tested. This is usually done to instrument the code so the example can observe calls made to other objects (like a mock). This is a pattern that I believe pre-dates mock objects, and is rarely implemented these days because mocks allow us to better separate things. Of course, this is a bit different from what's going on here. Here the example is being used as a delegate to handle services not available to the object. Named routes are made available to controller, view, and helper specs, so you can get them by either storing this file in any of those folders (spec/helpers, for example). HTH, David > it "should have a link" do > �[email protected] match /href/ > end > > ... But I get this error: > > NoMethodError in 'FooRenderer should have a link' > undefined method `foo_path' for > #<ActiveSupport::TestCase::Subclass_1:0x105619710> > > ... What can I include in my spec to get foo_path to be recognized? > _______________________________________________ rspec-users mailing list [email protected] http://rubyforge.org/mailman/listinfo/rspec-users
