squcumber-postgres 0.0.9 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e828300f0cb8a7c23134fb497f7c8db77b964fd1b1ecbd624133e1f43f6e9c8
|
4
|
+
data.tar.gz: 13a4b5d872b18ef71e6437cc4f73aa588054c720d36ef086822e74d6c605bde2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44cb35f73d0a380e2d8ceed798c25a2f4f80b07051ff3c485cf5618df67f817d3433c037a76f3a6265362fa86db8cbf7628ee0c2e71ff8338c9657883dc37a93
|
7
|
+
data.tar.gz: 87eb56e555d10ee0bd0924ea51985775583160764b025f7c8f2ba20a602724e39b06dc043bbb6274247be6f03f16ab778b038e859b8b8563027528529685accd
|
@@ -36,7 +36,7 @@ module Squcumber
|
|
36
36
|
|
37
37
|
def truncate_all_tables
|
38
38
|
@testing_database
|
39
|
-
.exec("select schemaname || '.' || tablename as schema_and_table from pg_tables where tableowner = '#{ENV['DB_USER']}'")
|
39
|
+
.exec("select schemaname || '.' || tablename as schema_and_table from pg_tables where tableowner = '#{ENV['DB_USER']}' and schemaname not in ('pg_catalog', 'information_schema')")
|
40
40
|
.map { |row| row['schema_and_table'] }
|
41
41
|
.each { |schema_and_table| exec("truncate table #{schema_and_table}") }
|
42
42
|
end
|
@@ -113,6 +113,8 @@ Then(/^the result( with date placeholders)? starts with.*$/) do |placeholder, da
|
|
113
113
|
expected = data.hashes || []
|
114
114
|
expected = convert_mock_values(expected) if placeholder
|
115
115
|
|
116
|
+
sanity_check_result(actual, expected)
|
117
|
+
|
116
118
|
expected.each_with_index do |hash, i|
|
117
119
|
raise("Does not start with expected result, got:\n#{format_error(data, actual)}") unless actual[i].all? do |key, value|
|
118
120
|
values_match(value, hash[key]) # actual,expected
|
@@ -125,10 +127,12 @@ Then(/^the result( with date placeholders)? includes.*$/) do |placeholder, data|
|
|
125
127
|
expected = data.hashes || []
|
126
128
|
expected = convert_mock_values(expected) if placeholder
|
127
129
|
|
130
|
+
sanity_check_result(actual, expected)
|
131
|
+
|
128
132
|
expected.each do |hash|
|
129
133
|
raise("Result is not included, got:\n#{format_error(data, actual)}") unless actual.any? do |row|
|
130
134
|
row.all? do |key, value|
|
131
|
-
values_match(value, hash[key]) # actual,expected
|
135
|
+
values_match(value, hash[key]) # actual, expected
|
132
136
|
end
|
133
137
|
end
|
134
138
|
end
|
@@ -139,6 +143,8 @@ Then(/^the result( with date placeholders)? does not include.*$/) do |placeholde
|
|
139
143
|
expected = data.hashes || []
|
140
144
|
expected = convert_mock_values(expected) if placeholder
|
141
145
|
|
146
|
+
sanity_check_result(actual, expected)
|
147
|
+
|
142
148
|
expected.each do |hash|
|
143
149
|
raise("Result is included, got:\n#{format_error(data, actual)}") if actual.any? do |row|
|
144
150
|
row.all? do |key, value|
|
@@ -153,6 +159,8 @@ Then(/^the result( with date placeholders)? exactly matches.*$/) do |placeholder
|
|
153
159
|
expected = data.hashes || []
|
154
160
|
expected = convert_mock_values(expected) if placeholder
|
155
161
|
|
162
|
+
sanity_check_result(actual, expected)
|
163
|
+
|
156
164
|
raise("Does not match exactly, got:\n#{format_error(data, actual)}") if actual.length != expected.length
|
157
165
|
|
158
166
|
actual.each_with_index do |row, i|
|
@@ -1,4 +1,15 @@
|
|
1
1
|
module MatcherHelpers
|
2
|
+
def sanity_check_result(actual, expected)
|
3
|
+
raise("The returned result is empty") if actual.empty?
|
4
|
+
raise("No data provided for comparison") if expected.empty?
|
5
|
+
|
6
|
+
expected[0].keys.each do |expected_key|
|
7
|
+
unless actual[0].keys.include?(expected_key)
|
8
|
+
raise("Column name '#{expected_key}' does not exist in result.\nAvailable column names are #{actual[0].keys.join(', ')}")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
2
13
|
def values_match(actual, expected)
|
3
14
|
if expected.eql?('today')
|
4
15
|
actual.match(/#{Regexp.quote(Date.today.to_s)}/)
|
@@ -6,6 +17,10 @@ module MatcherHelpers
|
|
6
17
|
actual.match(/#{Regexp.quote((Date.today - 1).to_s)}/)
|
7
18
|
elsif expected.eql?('any_date')
|
8
19
|
actual.match(/^\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2}$/)
|
20
|
+
elsif expected.eql?('sometime today')
|
21
|
+
actual.match(/^#{Regexp.quote(Date.today.to_s)} \d{2}:\d{2}:\d{2}$/)
|
22
|
+
elsif expected.eql?('sometime yesterday')
|
23
|
+
actual.match(/^#{Regexp.quote((Date.today - 1).to_s)} \d{2}:\d{2}:\d{2}$/)
|
9
24
|
elsif expected.eql?('any_string')
|
10
25
|
true if actual.is_a?(String) or actual.nil?
|
11
26
|
elsif expected.eql?('false') or expected.eql?('true')
|
@@ -18,8 +33,6 @@ module MatcherHelpers
|
|
18
33
|
end
|
19
34
|
end
|
20
35
|
|
21
|
-
def timetravel(date, i, method); i > 0 ? timetravel(date.send(method.to_sym), i - 1, method) : date; end
|
22
|
-
|
23
36
|
def convert_mock_values(mock_data)
|
24
37
|
mock_data.map do |entry|
|
25
38
|
entry.each do |key, value|
|
@@ -61,35 +74,35 @@ module MatcherHelpers
|
|
61
74
|
when /today/
|
62
75
|
Date.today
|
63
76
|
when /yesterday/
|
64
|
-
|
77
|
+
Date.today.prev_day
|
65
78
|
when /tomorrow/
|
66
|
-
|
79
|
+
Date.today.next_day
|
67
80
|
when /last month/
|
68
|
-
|
81
|
+
Date.today.prev_month
|
69
82
|
when /next month/
|
70
|
-
|
83
|
+
Date.today.next_month
|
71
84
|
when /last year/
|
72
|
-
|
85
|
+
Date.today.prev_year
|
73
86
|
when /next year/
|
74
|
-
|
87
|
+
Date.today.next_year
|
75
88
|
when /\s*\d+\s+month(s)?\s+ago\s*?/
|
76
89
|
number_of_months = value.match(/\d+/)[0].to_i
|
77
|
-
|
90
|
+
Date.today.prev_month(number_of_months)
|
78
91
|
when /\s*\d+\s+day(s)?\s+ago\s*/
|
79
92
|
number_of_days = value.match(/\d+/)[0].to_i
|
80
|
-
|
93
|
+
Date.today.prev_day(number_of_days)
|
81
94
|
when /\s*\d+\s+year(s)?\s+ago\s*/
|
82
95
|
number_of_years = value.match(/\d+/)[0].to_i
|
83
|
-
|
96
|
+
Date.today.prev_year(number_of_years)
|
84
97
|
when /\s*\d+\s+month(s)?\s+from now\s*?/
|
85
98
|
number_of_months = value.match(/\d+/)[0].to_i
|
86
|
-
|
99
|
+
Date.today.next_month(number_of_months)
|
87
100
|
when /\s*\d+\s+day(s)?\s+from now\s*/
|
88
101
|
number_of_days = value.match(/\d+/)[0].to_i
|
89
|
-
|
102
|
+
Date.today.next_day(number_of_days)
|
90
103
|
when /\s*\d+\s+year(s)?\s+from now\s*/
|
91
104
|
number_of_years = value.match(/\d+/)[0].to_i
|
92
|
-
|
105
|
+
Date.today.next_year(number_of_years)
|
93
106
|
else
|
94
107
|
placeholder
|
95
108
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: squcumber-postgres
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefanie Grunwald
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|
@@ -166,8 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
166
166
|
- !ruby/object:Gem::Version
|
167
167
|
version: '0'
|
168
168
|
requirements: []
|
169
|
-
|
170
|
-
rubygems_version: 2.7.6
|
169
|
+
rubygems_version: 3.0.3
|
171
170
|
signing_key:
|
172
171
|
specification_version: 3
|
173
172
|
summary: Define and execute SQL integration tests for Postgres databases
|