Uploaded image for project: 'Ruby Driver'
  1. Ruby Driver
  2. RUBY-1752

Mocking Time.now, reusing and mutating the mock value can break tests

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Critical - P2 Critical - P2
    • 2.7.2, 2.8.0
    • Affects Version/s: 2.7.0
    • Component/s: None
    • None

      I have a branch that tries to upgrade to 2.7.0 but we are getting sporadic test failures of "can't modify frozen Time" that look like this:

      # Braze's code
      Failure/Error: date = Time.now.utc.at_midnight()
           
           RuntimeError:
             can't modify frozen Time
      

      It's sporadic but only happens when we have a stubbing out of Time.now, like

      let!(:now) {Time.now}
      before :each do
        allow(Time).to receive(:now).and_return(now)
      end
      

      I think it comes from this commit which does a `Time.now.freeze`. Is it possible to dup the time?

      https://github.com/mongodb/mongo-ruby-driver/commit/80f369b35c30e15219f73c8796a3bc6522aa9f1f

            Assignee:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Reporter:
            jonhyman Jon Hyman
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: