timecop icon indicating copy to clipboard operation
timecop copied to clipboard

Allow unblocked freeze/travel when already in a freeze block?

Open tmorris-fiksu opened this issue 10 years ago • 2 comments

If Timecop is already frozen within a block, shouldn't future unblocked freeze and travel calls be considered "safe"? Here's an example of where I would find this construct useful:

    it "is a shame" do
      Timecop.safe_mode = true
      expect(Object).to receive(:bar) { Timecop.freeze(Time.now.utc + 10) }
      Timecop.freeze do
        old_time = Time.now.utc
        Object.bar
        expect(old_time).to eq Time.now.utc - 10
      end
    end

tmorris-fiksu avatar Feb 08 '15 20:02 tmorris-fiksu

+1

I have some specs that freeze time using a block, then travel:

it 'tests timey wimey stuff' do
  Timecop.freeze do
    assert_time_based_stuff
    Timecop.travel 1.day.from_now
    assert_more_time_based_stuff
  end
end

This currently blows up when in safe mode, but I feel like it shouldn't.

anujbiyani avatar Mar 11 '15 19:03 anujbiyani

+1

Tired of having ridiculous nestings as a result.

ballcheck avatar Oct 25 '16 10:10 ballcheck