timecop icon indicating copy to clipboard operation
timecop copied to clipboard

timezone is not stubbed correctly when traveling

Open grosser opened this issue 9 years ago • 4 comments

this works, but timecop did not :(

DateTime.stubs(:now).returns DateTime.parse("2015-01-01").utc

want a PR to stub correctly with zone .... or is this a 'feature' ?

grosser avatar Aug 25 '15 23:08 grosser

Please provide complete repro steps, including environment info (like your Ruby version, machine-local timezone, the value of your TZ environment variable (if set), and any libraries you have loaded that may interfere (e.g., ActiveSupport), including versions. It's also helpful to provide a clear definition of what you're expecting; without context, the phrase 'this works' isn't always immediately or unambiguously clear.

yaauie avatar Aug 25 '15 23:08 yaauie

I assume that means 'it should be working' I'll try to make a failing test case ... FYI currently 1 test fails when run in PDT ... I'll see if I can fix that too ...

TestTimeStackItem#test_timezones_apply_dates [time_stack_item_test.rb:187]:
Expected: Thu, 03 Jan 2013
  Actual: Wed, 02 Jan 2013

... fixed in https://github.com/travisjeffery/timecop/pull/164

grosser avatar Aug 26 '15 04:08 grosser

failing testcase: https://github.com/travisjeffery/timecop/pull/165

I was expecting this to flip me to the given timezone ... but it did not ... so I did a stubs(:now) to get it working in my tests, but ideally I'd like timecop to just switch to the timezone I give it ...

grosser avatar Aug 27 '15 04:08 grosser

I think this is related so I don't need to open a new issue:

  describe '::freeze with block' do
    let!(:tomorrow) { DateTime.now.in_time_zone.next.jd }

    subject { DateTime.now.in_time_zone.jd }

    Timecop.freeze(1.day.from_now) do
      it 'pretends today is tomorrow' do
        is_expected.to eq tomorrow
      end
    end
  end

  describe '::freeze without block' do
    let!(:tomorrow) { DateTime.now.in_time_zone.next.jd }

    before { Timecop.freeze(1.day.from_now) }
    after  { Timecop.return }

    subject { DateTime.now.in_time_zone.jd }

    it 'pretends today is tomorrow' do
      is_expected.to eq tomorrow
    end
  end

(I'm using #jd to only consider the date, and #strftime is too long to write :))

The first test fails, while the second one passes successfully.

RoxasShadow avatar Nov 18 '15 16:11 RoxasShadow