<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html; charset=ISO-8859-1"
 http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Hi People,<br>
<br>
<i>"Timecop is great and makes all these problems go away."</i><br>
<b>Tom Stuart</b><br>
<b>C 2nd Aug 2010 AD</b><br>
<br>
Thanks Paul and others, timecop did indeed make the problems go away.<br>
<br>
Here's what I've done:<br>
<br>
<tt>When /^At "([^\"]*)" I go to (.*)$/ do |time_string, page_name|<br>
  Timecop.travel(time_string) do<br>
    When "I go to #{page_name}"<br>
  end<br>
end</tt><br>
<br>
So then I can call the step:<br>
<br>
<tt>When At "10-10-2010 13:00:00" I go to the home page<br>
</tt><br>
And everything works perfectly.<br>
<br>
<br>
Thanks people, I'll leave you with the obligatory (terrible) Timecop
quote:<br>
<br>
<meta charset="utf-8">
<span class="Apple-style-span"
 style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Times; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;"><span
 class="Apple-style-span"
 style="font-family: Arial,Helvetica,sans-serif; font-size: 13px; line-height: 17px;"><b><a
 href="/name/nm0798779/" style="color: rgb(0, 51, 153);">McComb</a></b>:
That's C-4. Not only will it turn this house into dust, but it will
also separate every part of you from every other part of you.<span
 class="Apple-converted-space"> </span></span></span><br>
<br>
Will<br>
<br>
<br>
<br>
<br>
<br>
On 02/08/2010 10:52, Paul Bowsher wrote:
<blockquote
 cite="mid:AANLkTinYKEsK3TqoD7wcGTTxb9CV0hEgGUXDRWcd+9vh@mail.gmail.com"
 type="cite">Have you tried Timecop instead? <a moz-do-not-send="true"
 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 moz-do-not-send="true"
 href="mailto:will.tomlins@unboxedconsulting.com">will.tomlins@unboxedconsulting.com</a>></span>
wrote:<br>
  <blockquote class="gmail_quote"
 style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; 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 moz-do-not-send="true"
 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 moz-do-not-send="true"
 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 moz-do-not-send="true"
 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 moz-do-not-send="true" href="mailto:Chat@lists.lrug.org">Chat@lists.lrug.org</a><br>
    <a moz-do-not-send="true"
 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>
  <pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
Chat mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Chat@lists.lrug.org">Chat@lists.lrug.org</a>
<a class="moz-txt-link-freetext" href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a>
  </pre>
</blockquote>
<br>
</body>
</html>