Have you tried Timecop instead? <a href="http://github.com/jtrupiano/timecop">http://github.com/jtrupiano/timecop</a><div><br></div><div>I'm using it (not within Cucumber, mind) and it works great.</div><div><br clear="all">
Paul Bowsher<br>
<br><br><div class="gmail_quote">On Mon, Aug 2, 2010 at 10:50 AM, Will Tomlins <span dir="ltr"><<a href="mailto:will.tomlins@unboxedconsulting.com">will.tomlins@unboxedconsulting.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div>
Hi People,<br>
<br>
I'm having a strange issue with stubbing time and I was wondering if
anyone here could shed a little light on the issue.<br>
<br>
Firstly I am trying to stub Time.zone.now in Cucumber # Waits while
the calls of "<i>don't stub time in cucumber</i>" die down #. So the
feature I'm writing explicitly required different behaviour based on
the current time, and I would like the language of the feature to
reflect this.<br>
<br>
What I have at the moment:<br>
<tt><br>
When /^I time-travel to "([^\"]*)"$/ do |time_string|<br>
time = Time.zone.parse(time_string)<br>
Time.zone.stub!(:now).and_return(time)<br>
end<br>
<br>
Then "I return to the present day" do<br>
Time.zone.unstub!(:now)<br>
end<br>
</tt><br>
And my features go along these lines:<br>
<tt><br>
When I time-travel to "2010/01/01 10:00:00"<br>
And I go to the home page<br>
Then I should see XXXXXXXXXXXXXXXXXXX<br>
Then </tt><tt>I return to the present day</tt><br>
<br>
<br>
And I've got 2 scenarios running which use these quantum leaps. Each
scenario runs and passes when run on their own, but the second will
fail if the two are run together. After a bit more digging I found
that Time.zone.now cannot be stubbed if it has previously been
unstubbed.<br>
<br>
Thus:<tt><br>
<br>
</tt><tt>(rdb:1) Time.zone.stub!(:now).and_return(:something)<br>
#<a href="mailto:Proc:0x051b55a8@/Users/will/Sites/five-tv/vendor/gems/rspec-1.3.0/lib/spec/mocks/message_expectation.rb:61" target="_blank"><Proc:0x051b55a8@/Users/will/Sites/five-tv/vendor/gems/rspec-1.3.0/lib/spec/mocks/message_expectation.rb:61></a><br>
(rdb:1) Time.zone.now<br>
:something<br>
<br>
(rdb:1) Time.zone.stub!(:now).and_return(:something_else)<br>
#<a href="mailto:Proc:0x051b55a8@/Users/will/Sites/five-tv/vendor/gems/rspec-1.3.0/lib/spec/mocks/message_expectation.rb:61" target="_blank"><Proc:0x051b55a8@/Users/will/Sites/five-tv/vendor/gems/rspec-1.3.0/lib/spec/mocks/message_expectation.rb:61></a><br>
(rdb:1) Time.zone.now<br>
:something_else<br>
<br>
(rdb:1) Time.zone.unstub!(:now)<br>
#<Spec::Mocks::MessageExpectation:0x512c5dc @at_most=nil,
@exception_to_raise=nil, @args_to_yield_were_cloned=false.......<br>
(rdb:1) Time.zone.now<br>
Mon, 02 Aug 2010 10:28:56 BST +01:00<br>
<br>
(rdb:1) Time.zone.stub!(:now).and_return(:another_thing)<br>
#<a href="mailto:Proc:0x051b55a8@/Users/will/Sites/five-tv/vendor/gems/rspec-1.3.0/lib/spec/mocks/message_expectation.rb:61" target="_blank"><Proc:0x051b55a8@/Users/will/Sites/five-tv/vendor/gems/rspec-1.3.0/lib/spec/mocks/message_expectation.rb:61></a><br>
(rdb:1) Time.zone.now<br>
Mon, 02 Aug 2010 10:29:12 BST +01:00<br>
</tt><br>
I have to unstub because the time stub seems to carry across scenarios.<br>
<br>
Has anyone else had this issue, or know of any other way to decently
handle present time in cucumber?<br>
<br>
Thanks,<br>
Will<br>
<br>
<br>
</div>
<br>_______________________________________________<br>
Chat mailing list<br>
<a href="mailto:Chat@lists.lrug.org">Chat@lists.lrug.org</a><br>
<a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org" target="_blank">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a><br>
<br></blockquote></div><br></div>