[rspec-users] A better way to stub out constants

Lance Carlson lancecarlson at gmail.com
Wed Oct 31 23:37:12 EDT 2007


Nevermind, my bad.. the test was perfect.. my code was doing something crazy

On 10/31/07, Lance Carlson <lancecarlson at gmail.com> wrote:
> I followed this step by step:
>
>     Object.class_eval { remove_const :RMovie }
>
>     @ffm = mock("RMovie Movie Class")
>
>     RMovie = Module.new
>     RMovie::Movie = Class.new
>     RMovie::Movie.stub!(:new).and_return(@ffm)
>
> and I got a 'stack level too deep' error on the last line. Anyone have
> any ideas?
>
> On 10/31/07, Ashley Moran <work at ashleymoran.me.uk> wrote:
> >
> > On Oct 31, 2007, at 9:59 pm, Shane Mingins wrote:
> >
> > > Similar to my MiddleMan stub .... I used
> > >
> > > class Object;  remove_const :MiddleMan; end
> > >
> > > Not sure how kosha it is?
> >
> >
> > Hi Shane
> >
> > That was my actually my solution in the end, but I didn't post back to
> > the list.  To be honest, I don't think anything that messes with the
> > global namespace is kosha, but I guess it's something we've got to
> > live with.  (You often have to do worse stuff to test Rails, which
> > makes me feel better.)
> >
> > I actually summarised the few steps I needed to take on my blog:
> > <http://aviewfromafar.net/2007/10/31/specifying-dynamic-gem-usage-with-rspec
> >  >
> >
> > Quite why I thought it was interesting enough to tell the google bots
> > but not interesting enough to tell the RSpec list, I don't know...
> >
> > Cheers
> > Ashley
> >
> >
> > --
> > blog @ http://aviewfromafar.net/
> > linked-in @ http://www.linkedin.com/in/ashleymoran
> > currently @ home
> >
> > _______________________________________________
> > rspec-users mailing list
> > rspec-users at rubyforge.org
> > http://rubyforge.org/mailman/listinfo/rspec-users
> >
>


More information about the rspec-users mailing list