Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set time zone on one rspec test

I am trying to set the time zone on one rspec test in this way:

zone = ActiveSupport::TimeZone.new('Hawaii')
Time.stub(:now) { Time.now.in_time_zone(zone) }

This gives me a stack level too deep error, what am I missing here?

like image 790
trueinViso Avatar asked Nov 04 '14 17:11

trueinViso


1 Answers

Try doing this:

zone = ActiveSupport::TimeZone.new('Hawaii')
Time.stub(:now){ Time.new.in_time_zone(zone) }

I am not sure, but it seems like stubbing now and then calling Time.now in block is causing stack level too deep error.

like image 113
Surya Avatar answered Nov 12 '22 12:11

Surya