Skip to content

Commit 3d88391

Browse files
committed
Fuzzy match today and yesterday
In case of e.g. using now() or current_timestamp() in the query, it's hard to determine the exact hour, minute and seconds of execution for the comparison. In these cases, using a fuzzy matcher such as "sometime today" should be enough to ensure that the query works as designed, without adding too much overhead for e.g. mocking out core functions of the database.
1 parent 6e6bdee commit 3d88391

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

lib/squcumber-postgres/support/matchers.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ def values_match(actual, expected)
66
actual.match(/#{Regexp.quote((Date.today - 1).to_s)}/)
77
elsif expected.eql?('any_date')
88
actual.match(/^\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2}$/)
9+
elsif expected.eql?('sometime today')
10+
actual.match(/^#{Regexp.quote(Date.today.to_s)} \d{2}:\d{2}:\d{2}$/)
11+
elsif expected.eql?('sometime yesterday')
12+
actual.match(/^#{Regexp.quote((Date.today - 1).to_s)} \d{2}:\d{2}:\d{2}$/)
913
elsif expected.eql?('any_string')
1014
true if actual.is_a?(String) or actual.nil?
1115
elsif expected.eql?('false') or expected.eql?('true')

0 commit comments

Comments
 (0)