I''m writing a controller which should only be inherited from, something like the generic crud controller seen here: http:// geekonomics.blogspot.com/2006/07/crud-and-shared-controllers.html Now, in my spec, I would like to create a controller which inherits from the generic CRUDController, without actually creating the controller. This controller is *only* for testing. How can I do this? I can''t do something like this: Object.const_set("MyCrudController", Class.new(CRUDController)) because the method "controller_name" will complain of setting the constant twice. Any ideas? Best, Scott Taylor
David Chelimsky
2007-Mar-19 11:10 UTC
[rspec-users] controller_name with dynamic controllers
On 3/19/07, Scott Taylor <mailing_lists at railsnewbie.com> wrote:> > I''m writing a controller which should only be inherited from, > something like the generic crud controller seen here: http:// > geekonomics.blogspot.com/2006/07/crud-and-shared-controllers.html > > Now, in my spec, I would like to create a controller which inherits > from the generic CRUDController, without actually creating the > controller. This controller is *only* for testing. > > How can I do this? I can''t do something like this: > > Object.const_set("MyCrudController", Class.new(CRUDController))unless defined?(TestingCrudController) TestingCrudController = Class.new(CRUDController) end> > because the method "controller_name" will complain of setting the > constant twice. > > Any ideas? > > Best, > > Scott Taylor > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Thanks for the reply. Actually, both work, but I was making the dumb move of using be_equal instead of be ==, so I was getting a failing spec. Scott On Mar 19, 2007, at 7:10 AM, David Chelimsky wrote:> On 3/19/07, Scott Taylor <mailing_lists at railsnewbie.com> wrote: >> >> I''m writing a controller which should only be inherited from, >> something like the generic crud controller seen here: http:// >> geekonomics.blogspot.com/2006/07/crud-and-shared-controllers.html >> >> Now, in my spec, I would like to create a controller which inherits >> from the generic CRUDController, without actually creating the >> controller. This controller is *only* for testing. >> >> How can I do this? I can''t do something like this: >> >> Object.const_set("MyCrudController", Class.new(CRUDController)) > > unless defined?(TestingCrudController) > TestingCrudController = Class.new(CRUDController) > end > >> >> because the method "controller_name" will complain of setting the >> constant twice. >> >> Any ideas? >> >> Best, >> >> Scott Taylor >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
David Chelimsky
2007-Mar-19 12:16 UTC
[rspec-users] controller_name with dynamic controllers
On 3/19/07, Scott Taylor <mailing_lists at railsnewbie.com> wrote:> > Thanks for the reply. Actually, both work, but I was making the dumb > move of using be_equal instead of be ==, so I was getting a failing > spec.FWIW, be == is not really supported. You should just use == ... actual.should == expected or actual.should equal(expected) if you want object identity.> > Scott > > > On Mar 19, 2007, at 7:10 AM, David Chelimsky wrote: > > > On 3/19/07, Scott Taylor <mailing_lists at railsnewbie.com> wrote: > >> > >> I''m writing a controller which should only be inherited from, > >> something like the generic crud controller seen here: http:// > >> geekonomics.blogspot.com/2006/07/crud-and-shared-controllers.html > >> > >> Now, in my spec, I would like to create a controller which inherits > >> from the generic CRUDController, without actually creating the > >> controller. This controller is *only* for testing. > >> > >> How can I do this? I can''t do something like this: > >> > >> Object.const_set("MyCrudController", Class.new(CRUDController)) > > > > unless defined?(TestingCrudController) > > TestingCrudController = Class.new(CRUDController) > > end > > > >> > >> because the method "controller_name" will complain of setting the > >> constant twice. > >> > >> Any ideas? > >> > >> Best, > >> > >> Scott Taylor > >> > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-users at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/rspec-users > >> > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >