Skip to content

Add RSpec metadata tags for time traveling around specs

Dallas Reedy requested to merge add-rspec-tag-for-freezing-time into master

What does this MR do and why?

Creates a set of new metadata tags in RSpec that can be used to easily time travel around a spec or group of specs.

A key benefit of doing so is that we abstract the act of time traveling from the actual instances of doing so. Doing this reduces the amount of work involved if we ever switch time-traveling strategies again.

:freeze_time

RSpec.describe SomeTest do
  around do |example|
    freeze_time { example.run }
  end

  # specs ...
end

# BECOMES

RSpec.describe SomeTest, :freeze_time do
  # specs ...
end

:time_travel

RSpec.describe SomeTest do
  around do |example|
    travel(3.days) { example.run }
  end

  # specs ...
end

# BECOMES

RSpec.describe SomeTest, time_travel: 3.days do
  # specs ...
end

:time_travel_to

RSpec.describe SomeTest do
  around do |example|
    travel_to('2020-01-01') { example.run }
  end

  # specs ...
end

# BECOMES

RSpec.describe SomeTest, time_travel_to: '2020-01-01' do
  # specs ...
end

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Dallas Reedy

Merge request reports