I have two projects running Rails 4.2 and using travel_to
from ActiveSupport::Testing::TimeHelpers.
In one project everything is working perfectly. But in the second one,
my
specs are running with the current date/time instead of using travel_to.
Here is one example:
it “is only a travel_to test” do
travel_to Time.new(2012, 1, 1, 1, 1, 1) do
expect(Time.new).to eq Time.new(2012, 1, 1, 1, 1, 1)
end
end
I’ve already set the rails_helper.rb with:
RSpec.configure do |config|
…
config.include ActiveSupport::Testing::TimeHelpers
end
On Tue, Feb 17, 2015 at 5:03 PM, Cezinha A. [email protected]
wrote:
I have two projects running Rails 4.2 and using travel_to from
ActiveSupport::Testing::TimeHelpers.
it “is only a travel_to test” do
travel_to Time.new(2012, 1, 1, 1, 1, 1) do
expect(Time.new).to eq Time.new(2012, 1, 1, 1, 1, 1)
end
end
From the doc for travel_to –
Changes current time to the given time by stubbing Time.now and
Date.today to return the time or date passed into this method.
If you change your test to expect(Time.now).to ... it will pass.
It is initialized to the current system time if no argument is given.
a = Time.new #=> 2007-11-19 07:50:02 -0600
Yes, you are right, and since that document also says that Time.now is
an alias for this, and the docs for travel_to states that Time.now
should get the travel_to time (have you tried Time.now in the block?)
then it looks like you have found a bug.
I think I have to retract this, since the docs for travel_to state
that Time.now and Time.current are stubbed then it means that Time.now
is no longer an alias for Time.new(), so there is no guarantee that
Time.new() will respect travel_to.
On 18 February 2015 at 12:04, Cezinha - ASSEINFO [email protected]
wrote:
It is initialized to the current system time if no argument is given.
a = Time.new #=> 2007-11-19 07:50:02 -0600
Yes, you are right, and since that document also says that Time.now is
an alias for this, and the docs for travel_to states that Time.now
should get the travel_to time (have you tried Time.now in the block?)
then it looks like you have found a bug.