diff options
author | Nick Thomas <nick@gitlab.com> | 2016-10-17 15:40:02 +0300 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2016-10-17 16:44:20 +0300 |
commit | bfb20200e9d1e7edd82a27d18d849ffba043845a (patch) | |
tree | 28f614cb61db165c8ebf1524d981e91755bec17f /spec/support/matchers | |
parent | 77507df6030dad9e317e092c70003d4c85d8f889 (diff) |
Add a be_like_time matcher and use it in specs
The amount of precision times have in databases is variable, so we need
tolerances when comparing in specs. It's better to have the tolerance defined
in one place than several.
Diffstat (limited to 'spec/support/matchers')
-rw-r--r-- | spec/support/matchers/be_like_time.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/spec/support/matchers/be_like_time.rb b/spec/support/matchers/be_like_time.rb new file mode 100644 index 00000000000..1f27390eab7 --- /dev/null +++ b/spec/support/matchers/be_like_time.rb @@ -0,0 +1,13 @@ +RSpec::Matchers.define :be_like_time do |expected| + match do |actual| + expect(actual).to be_within(1.second).of(expected) + end + + description do + "within one second of #{expected}" + end + + failure_message do |actual| + "expected #{actual} to be within one second of #{expected}" + end +end |