Consider: module X def initialize(a) super() end end describe X do it "is a module" do X.should be_instance_of(Module) end end This generates an error because #describe tries to include X into the test harness and the test harness doesn''t know about the extra argument to #initialize. The work around is to just use ''describe "X" do'' but I spent a bit of time just trying to figure out what was going on. Why is #describe trying to include the module? Gary Wright
On Feb 16, 2008 5:19 PM, Gary Wright <gwtmp01 at mac.com> wrote:> Consider: > > module X > def initialize(a) > super() > end > end > > describe X do > > it "is a module" do > X.should be_instance_of(Module) > end > end > > This generates an error because #describe tries to include X into the > test harness and the test harness doesn''t know about the extra > argument to #initialize. > > The work around is to just use ''describe "X" do'' but I spent a bit of > time just trying to figure out what was going on. > > Why is #describe trying to include the module?That was done initially to support Rails helper specs. As it turns out, I usually wrap add a #helper method that returns self in those cases to make it explicit. So I''m not sure of it''s value, but removing it (unfortunately) would probably break myriad specs out there. We should definitely improve the docs though. HTH, David> > Gary Wright > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
On Feb 16, 2008, at 6:10 PM, David Chelimsky wrote:> That was done initially to support Rails helper specs. As it turns > out, I usually wrap add a #helper method that returns self in those > cases to make it explicit. So I''m not sure of it''s value, but removing > it (unfortunately) would probably break myriad specs out there. > > We should definitely improve the docs though.It is quite odd. Perhaps a flag and/or alternate method name to turn off that behavior? In my case my module also extends the including module with class methods so it seems like a great way to get some pretty obscure name clashes. Gary Wright
On Feb 17, 2008 12:59 AM, Gary Wright <gwtmp01 at mac.com> wrote:> > On Feb 16, 2008, at 6:10 PM, David Chelimsky wrote: > > That was done initially to support Rails helper specs. As it turns > > out, I usually wrap add a #helper method that returns self in those > > cases to make it explicit. So I''m not sure of it''s value, but removing > > it (unfortunately) would probably break myriad specs out there. > > > > We should definitely improve the docs though. > > It is quite odd. Perhaps a flag and/or alternate method name to turn > off that behavior? In my case my module also extends the including > module with class methods so it seems like a great way to get some > pretty obscure name clashes.Personally I''d just as soon deprecate it rather than add a flag. Let me write up a separate email to get feedback on this.> > > Gary Wright > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >