Created
October 22, 2021 15:11
-
-
Save jamescmartinez/82eaf14dc3c71a922fbb922c146754c0 to your computer and use it in GitHub Desktop.
RSpec time comparison matcher to 6 decimal places
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# On MacOS, time has a precision of 6. On Linux (e.g. CI), time is more precise. | |
# | |
# For example: | |
# Linux: Fri, 22 Oct 2021 11:24:40.219256519 UTC +00:00 | |
# MacOS: Fri, 22 Oct 2021 11:24:40.219256000 UTC +00:00 | |
# | |
# This matcher compares time with a precision of 6 decimal places to prevent | |
# time comparison failures in CI. | |
# | |
RSpec::Matchers.define(:eq_time) do |expected| | |
match do |actual| | |
expected.iso8601(6) == actual.iso8601(6) | |
end | |
failure_message do |actual| | |
"expected #{actual.iso8601(6)} to equal time #{expected.iso8601(6)}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment