File tree 1 file changed +36
-0
lines changed
1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Thanks to ManageIQ team for the be_same_time_as matcher, see
2
+ # https://github.com/ManageIQ/manageiq/blob/f647d72ec6f8ba644d753fb041c8ecad277c3ef4/spec/support/custom_matchers/be_same_time_as.rb
3
+ RSpec ::Matchers . define :be_same_time_as do |expected |
4
+ match do |actual |
5
+ actual . round ( precision ) == expected . round ( precision )
6
+ end
7
+
8
+ failure_message do |actual |
9
+ "\n expected: #{ format_time ( expected ) } ,\n " \
10
+ "got: #{ format_time ( actual ) } \n \n (compared using be_same_time_as with precision of #{ precision } )"
11
+ end
12
+
13
+ failure_message_when_negated do
14
+ "\n expected different time from #{ format_time ( expected ) } \n \n " \
15
+ "(compared using be_same_time_as with precision of #{ precision } )"
16
+ end
17
+
18
+ description do
19
+ "be the same time as #{ format_time ( expected ) } to #{ precision } digits of precision"
20
+ end
21
+
22
+ def with_precision ( p )
23
+ @precision = p
24
+ self
25
+ end
26
+
27
+ def precision
28
+ @precision ||= 5
29
+ end
30
+
31
+ private
32
+
33
+ def format_time ( t )
34
+ "#<#{ t . class } #{ t . iso8601 ( 10 ) } >"
35
+ end
36
+ end
You can’t perform that action at this time.
0 commit comments