# Rails 4.2 & travel\_to is not working

**URL:** <https://www.ruby-forum.com/t/rails-4-2-travel-to-is-not-working/234235>\
**Category:** Rails\
**Created:** [February 18, 2015, 2:04am UTC](https://www.ruby-forum.com/t/rails-4-2-travel-to-is-not-working/234235 "2015-02-18T02:04:53Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![addis\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@addis\_a](https://www.ruby-forum.com/u/addis_a)\
**Post date:** [February 18, 2015, 2:04am UTC](https://www.ruby-forum.com/t/rails-4-2-travel-to-is-not-working/234235/1 "2015-02-18T02:04:53Z")

</div>

Hi!

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

Does anyone know what’s going on?

Thanks.

---

<div class="post-metadata">

**Author:** ![Cezinha\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9f8e36/32.png) [@Cezinha\_A](https://www.ruby-forum.com/u/Cezinha_A)\
**Post date:** [February 18, 2015, 10:22am UTC](https://www.ruby-forum.com/t/rails-4-2-travel-to-is-not-working/234235/2 "2015-02-18T10:22:00Z")

</div>

On 18 February 2015 at 01:03, Cezinha A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> ```
> travel_to Time.new(2012, 1, 1, 1, 1, 1) do
> 
> ```
> 
> Does anyone know what’s going on?

What do Time.current and Time.now give you inside the block?

Colin

---

<div class="post-metadata">

**Author:** ![Cezinha\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9f8e36/32.png) [@Cezinha\_A](https://www.ruby-forum.com/u/Cezinha_A)\
**Post date:** [February 18, 2015, 12:05pm UTC](https://www.ruby-forum.com/t/rails-4-2-travel-to-is-not-working/234235/3 "2015-02-18T12:05:17Z")

</div>

Bingo!

It’s returning the “travel\_to” time.

Do you know why?

Thanks A LOT!!!

Em Wed Feb 18 2015 at 7:20:47 AM, Colin L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
escreveu:

---

<div class="post-metadata">

**Author:** ![Cezinha\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9f8e36/32.png) [@Cezinha\_A](https://www.ruby-forum.com/u/Cezinha_A)\
**Post date:** [February 18, 2015, 12:10pm UTC](https://www.ruby-forum.com/t/rails-4-2-travel-to-is-not-working/234235/4 "2015-02-18T12:10:33Z")

</div>

On 18 February 2015 at 11:03, Cezinha - ASSEINFO [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Bingo!
> 
> It’s returning the “travel\_to” time.
> 
> Do you know why?

Can you point to some documentation that says that Time.new()  
initialises to current? I could not find any.

Colin

---

<div class="post-metadata">

**Author:** ![Cezinha\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9f8e36/32.png) [@Cezinha\_A](https://www.ruby-forum.com/u/Cezinha_A)\
**Post date:** [February 18, 2015, 1:05pm UTC](https://www.ruby-forum.com/t/rails-4-2-travel-to-is-not-working/234235/5 "2015-02-18T13:05:41Z")

</div>

You can find here:

> **[Class: Time (Ruby 2.2.0)](https://ruby-doc.org//core-2.2.0/Time.html)**
>
> Class : Time - Ruby 2.2.0

_new → time_

_new(year, month=nil, day=nil, hour=nil, min=nil, sec=nil,  
utc\_offset=nil)  
→ time_

Returns a Time [http://ruby-doc.org//core-2.2.0/Time.html](http://ruby-doc.org//core-2.2.0/Time.html) object.

It is initialized to the current system time if no argument is given.

a = Time.new _#=\> 2007-11-19 07:50:02 -0600_

Thanks.

Em Wed Feb 18 2015 at 9:09:31 AM, Colin L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
escreveu:

---

<div class="post-metadata">

**Author:** ![Cezinha\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9f8e36/32.png) [@Cezinha\_A](https://www.ruby-forum.com/u/Cezinha_A)\
**Post date:** [February 18, 2015, 2:31pm UTC](https://www.ruby-forum.com/t/rails-4-2-travel-to-is-not-working/234235/6 "2015-02-18T14:31:39Z")

</div>

On Tue, Feb 17, 2015 at 5:03 PM, Cezinha A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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.

## HTH,

Hassan S. ------------------------ [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[Hassan Schroeder | about.me](http://about.me/hassanschroeder)  
twitter: @hassan  
Consulting Availability : Silicon Valley or remote

---

<div class="post-metadata">

**Author:** ![Cezinha\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9f8e36/32.png) [@Cezinha\_A](https://www.ruby-forum.com/u/Cezinha_A)\
**Post date:** [February 18, 2015, 3:04pm UTC](https://www.ruby-forum.com/t/rails-4-2-travel-to-is-not-working/234235/7 "2015-02-18T15:04:07Z")

</div>

On 18 February 2015 at 12:23, Colin L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > Returns a Time object.
> > 
> > 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.

Colin

---

<div class="post-metadata">

**Author:** ![Cezinha\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9f8e36/32.png) [@Cezinha\_A](https://www.ruby-forum.com/u/Cezinha_A)\
**Post date:** [February 18, 2015, 1:25pm UTC](https://www.ruby-forum.com/t/rails-4-2-travel-to-is-not-working/234235/8 "2015-02-18T13:25:15Z")

</div>

On 18 February 2015 at 12:04, Cezinha - ASSEINFO [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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.

Colin

---

<div class="post-metadata">

**Author:** ![Cezinha\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9f8e36/32.png) [@Cezinha\_A](https://www.ruby-forum.com/u/Cezinha_A)\
**Post date:** [February 18, 2015, 3:43pm UTC](https://www.ruby-forum.com/t/rails-4-2-travel-to-is-not-working/234235/9 "2015-02-18T15:43:26Z")

</div>

Hi!

I changed my code to use Time.now instead of Time.new and now everything  
is  
ok.

Do you know where can I check if this bugs is reported and if no… to  
report?

Thanks.

Em Wed Feb 18 2015 at 12:03:06 PM, Colin L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
escreveu:

---

<div class="post-metadata">

**Author:** ![Cezinha\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9f8e36/32.png) [@Cezinha\_A](https://www.ruby-forum.com/u/Cezinha_A)\
**Post date:** [February 18, 2015, 3:55pm UTC](https://www.ruby-forum.com/t/rails-4-2-travel-to-is-not-working/234235/10 "2015-02-18T15:55:30Z")

</div>

On 18 February 2015 at 14:41, Cezinha - ASSEINFO [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Hi!
> 
> I changed my code to use Time.now instead of Time.new and now everything is  
> ok.
> 
> Do you know where can I check if this bugs is reported and if no… to  
> report?

Probably our posts crossed, see my last email for reason why I don’t  
think this is a bug.

Colin
