Adam,
What I usually do is extract out the original Time.now call to method
somewhere (with an intention revealing name) and stub out the method
instead of #now itself.
-----
BJ Clark
On Jul 13, 2009, at 9:45 AM, Adam Anderson wrote:
So that is what is happening now. Time.now is being stubbed but that
will last for the life of the spec, but I only need it to create
some test data and I don't want it to affect other areas of the app
after that test data has been created. Currently Time.now is being
used somewhere to create a guid (which is uhh... not a guid,
obviously). So if Time.now is stubbed then it will create the same
"guid" each time causing validation errors on that model. This is a
legacy piece of code but one that can't currently be removed so I'm
attempting to find a way around this issue, though I'd much rather
generate a real GUID or get rid of it altogether.
Thanks for the help!
On Mon, Jul 13, 2009 at 9:26 AM, doug livesey <biot...@gmail.com>
wrote:
Can you just stub it before the example in question, either in it or
in a before block?
2009/7/13 Adam Anderson <adamanderso...@gmail.com>
I can't seem to find a good way to do this. If I stub out Time.now
in one of my specs but need to return it to its original
functionality then can I remove the stub?
So I'd like to say something like:
Time.stub!(:now).and_return(foo_time)
Time.now # => foo_time
Time.unstub!(:now)
Time.now # => whatever time it actually is
Is this possible? I noticed $rspec_mocks.reset_all, but obviously I
don't want everything to go away, just this one stub.
-Adam
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users
-----
BJ Clark
AboutUs.Org
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users