Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Thomas <nick@gitlab.com>2016-10-17 15:40:02 +0300
committerNick Thomas <nick@gitlab.com>2016-10-17 16:44:20 +0300
commitbfb20200e9d1e7edd82a27d18d849ffba043845a (patch)
tree28f614cb61db165c8ebf1524d981e91755bec17f /spec/support/matchers
parent77507df6030dad9e317e092c70003d4c85d8f889 (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.rb13
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