squcumber-postgres 0.0.10 → 0.1.0

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: '0038fa696e028950ec11458f8ed21529e54447eccfe61b299f0746554104877d'
4
- data.tar.gz: f000dee57c42d995b90a55fc42a140421eb002222afb811cb9ab2a45bfc91cb0
3
+ metadata.gz: '089d8a3f411ec32c7b5915819d3da2691b91404397c2601c0468a3bebb1eb3ec'
4
+ data.tar.gz: 9842daf920c36ea783ba5e381993972cf71d323be275f4f47fed75729af05359
5
5
  SHA512:
6
- metadata.gz: 327f4629ce093e6e96251720d00d8154ef57e39d1a6a73b53ab0fd1c3bfef6d8ac5100687c2bb47b3b27ea4441b4bd8c3c35c1154c021d3ce784a38050217790
7
- data.tar.gz: b81e3a0f5cb8cc102d6d94ec4a93a44eddcb4500bef3ea4de7c2e12abf292f3b6a4153b53a17e46a9ed68305e598f8fa133271621905329e2e23622701fba7dd
6
+ metadata.gz: 698c9109d441bed70308522ed173a458ab78644127a56d610f1283bce68fe574a31a974873d1b303f97e01b5bc131e7d60c08b8e5be7fd6683302a5f473f66ea
7
+ data.tar.gz: 30cf3e31073c6fdf1fdc8d3051f19fde1c65545d75ad8b835d2535fe0332f3a2a92e59be22da5c72c1724a1e72d11ad287f7fe8986273016275139700d33de77
@@ -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')
@@ -70,6 +85,12 @@ module MatcherHelpers
70
85
  Date.today.prev_year
71
86
  when /next year/
72
87
  Date.today.next_year
88
+ when /\s*\d+\s+minute(s)?\s+ago\s*?/
89
+ number_of_minutes = value.match(/\d+/)[0].to_i
90
+ DateTime.now - (number_of_minutes/24.0/60.0)
91
+ when /\s*\d+\s+hours(s)?\s+ago\s*?/
92
+ number_of_hours = value.match(/\d+/)[0].to_i
93
+ DateTime.now - (number_of_hours/24.0)
73
94
  when /\s*\d+\s+month(s)?\s+ago\s*?/
74
95
  number_of_months = value.match(/\d+/)[0].to_i
75
96
  Date.today.prev_month(number_of_months)
@@ -79,6 +100,12 @@ module MatcherHelpers
79
100
  when /\s*\d+\s+year(s)?\s+ago\s*/
80
101
  number_of_years = value.match(/\d+/)[0].to_i
81
102
  Date.today.prev_year(number_of_years)
103
+ when /\s*\d+\s+minute(s)?\s+from now\s*?/
104
+ number_of_minutes = value.match(/\d+/)[0].to_i
105
+ DateTime.now + (number_of_minutes/24.0/60.0)
106
+ when /\s*\d+\s+hours(s)?\s+from now\s*?/
107
+ number_of_hours = value.match(/\d+/)[0].to_i
108
+ DateTime.now + (number_of_hours/24.0)
82
109
  when /\s*\d+\s+month(s)?\s+from now\s*?/
83
110
  number_of_months = value.match(/\d+/)[0].to_i
84
111
  Date.today.next_month(number_of_months)
@@ -182,7 +182,7 @@ module Squcumber::Postgres::Mock
182
182
  end
183
183
 
184
184
  it 'asks the testing database for currently existing tables in production schemas' do
185
- expect(testing_database).to have_received(:exec).with(/^\s*select\s+schemaname\s+\|\|\s+'\.'\s+\|\|\s+tablename\s+as schema\_and\_table\s+from\s+pg_tables\s+where\s+tableowner\s*=\s*'some_user'\s*;?\s*$/)
185
+ expect(testing_database).to have_received(:exec).with(/^\s*select\s+schemaname\s+\|\|\s+'\.'\s+\|\|\s+tablename\s+as schema\_and\_table\s+from\s+pg_tables\s+where\s+tableowner\s*=\s*'some_user'\s+and\s+schemaname\s+not\s+in\s+\('pg_catalog',\s+'information_schema'\s*\)\s*;?\s*$/)
186
186
  end
187
187
 
188
188
  it 'truncates the returned tables in the testing database' do
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.10
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefanie Grunwald
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-29 00:00:00.000000000 Z
11
+ date: 2021-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg
@@ -159,15 +159,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
159
159
  requirements:
160
160
  - - ">="
161
161
  - !ruby/object:Gem::Version
162
- version: '2.0'
162
+ version: '2.5'
163
163
  required_rubygems_version: !ruby/object:Gem::Requirement
164
164
  requirements:
165
165
  - - ">="
166
166
  - !ruby/object:Gem::Version
167
167
  version: '0'
168
168
  requirements: []
169
- rubyforge_project:
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