slacker 1.0.15 → 1.0.16
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 +4 -4
- data/bin/slacker +6 -0
- data/lib/slacker/application.rb +54 -8
- data/lib/slacker/configuration.rb +3 -1
- data/lib/slacker/query_result_matcher.rb +5 -0
- data/lib/slacker/version.rb +1 -1
- data/lib/slacker_new/project/database.yml +5 -0
- data/slacker.gemspec +2 -1
- data/spec/query_result_matcher_spec.rb +24 -0
- metadata +19 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e066024e6fc217c813e00bb3554ac60bf89dac3f
|
4
|
+
data.tar.gz: a51a29aeea274ca3324f483d285cc3fc4d807a97
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0f12d147aa478cf430eae96ce578956602d87fae99b3df3b5ebbf9528a3b53edf6a6d7afe208b4e79cd41e68f58dc94e828ecdd362df950e120c288bc9c4f29
|
7
|
+
data.tar.gz: d11db9e0dd45aa62ffbca4033ac6db5cc64433e31ad745aa9c970b486749496d33e97686564c4f83fdc46367b29f6264672b0a6531a9237f685b47c297d1250a
|
data/bin/slacker
CHANGED
@@ -23,6 +23,12 @@ Slacker.configure do |config|
|
|
23
23
|
config.db_name = db_config["database"]
|
24
24
|
config.db_user = db_config["user"]
|
25
25
|
config.db_password = db_config["password"]
|
26
|
+
if !!db_config["port"]
|
27
|
+
config.db_port = db_config["port"]
|
28
|
+
end
|
29
|
+
if !!db_config["driver"]
|
30
|
+
config.db_driver = db_config["driver"]
|
31
|
+
end
|
26
32
|
end
|
27
33
|
|
28
34
|
if Slacker.application.run
|
data/lib/slacker/application.rb
CHANGED
@@ -5,6 +5,7 @@ require 'slacker/rspec_monkey'
|
|
5
5
|
require 'slacker/rspec_ext'
|
6
6
|
require 'slacker/string_helper'
|
7
7
|
require 'odbc'
|
8
|
+
require 'tiny_tds'
|
8
9
|
|
9
10
|
module Slacker
|
10
11
|
class Application
|
@@ -25,12 +26,18 @@ set ansi_nulls on;
|
|
25
26
|
set concat_null_yields_null on;
|
26
27
|
EOF
|
27
28
|
|
29
|
+
ODBC_DRIVER = 'odbc'
|
30
|
+
TINYTDS_DRIVER = 'tiny_tds'
|
31
|
+
|
28
32
|
def initialize(configuration)
|
29
33
|
@configuration = configuration
|
30
34
|
@temp_folders = ['debug/passed_examples', 'debug/failed_examples']
|
31
35
|
@target_folder_structure = ['data', 'debug/passed_examples', 'debug/failed_examples', 'sql', 'spec', 'lib', 'lib/helpers']
|
32
36
|
@error_message = ''
|
33
|
-
@
|
37
|
+
case @configuration.db_driver
|
38
|
+
when ODBC_DRIVER
|
39
|
+
@database = ODBC::Database.new
|
40
|
+
end
|
34
41
|
end
|
35
42
|
|
36
43
|
def print_connection_message
|
@@ -49,8 +56,8 @@ EOF
|
|
49
56
|
run_rspec
|
50
57
|
false # Return false to be stored in error (effectively indicating no error).
|
51
58
|
end
|
52
|
-
|
53
|
-
|
59
|
+
ensure
|
60
|
+
cleanup_after_run
|
54
61
|
end
|
55
62
|
|
56
63
|
if @configuration.console_enabled
|
@@ -73,13 +80,23 @@ EOF
|
|
73
80
|
|
74
81
|
# Configure Slacker
|
75
82
|
def configure
|
76
|
-
|
83
|
+
case @configuration.db_driver
|
84
|
+
when ODBC_DRIVER
|
85
|
+
configure_db_odbc
|
86
|
+
when TINYTDS_DRIVER
|
87
|
+
configure_db_tiny_tds
|
88
|
+
end
|
77
89
|
configure_rspec
|
78
90
|
configure_misc
|
79
91
|
end
|
80
92
|
|
81
93
|
def cleanup_after_run
|
82
|
-
|
94
|
+
case @configuration.db_driver
|
95
|
+
when ODBC_DRIVER
|
96
|
+
@database.disconnect if (@database && @database.connected?)
|
97
|
+
when TINYTDS_DRIVER
|
98
|
+
@database.close if (@database && @database.active?)
|
99
|
+
end
|
83
100
|
end
|
84
101
|
|
85
102
|
def cleanup_folders
|
@@ -121,7 +138,7 @@ EOF
|
|
121
138
|
end
|
122
139
|
|
123
140
|
# Configure database connection
|
124
|
-
def
|
141
|
+
def configure_db_odbc
|
125
142
|
drv = ODBC::Driver.new
|
126
143
|
drv.name = 'Driver1'
|
127
144
|
drv.attrs.tap do |a|
|
@@ -140,8 +157,27 @@ EOF
|
|
140
157
|
end
|
141
158
|
end
|
142
159
|
|
160
|
+
def configure_db_tiny_tds
|
161
|
+
begin
|
162
|
+
@database = TinyTds::Client.new :username => @configuration.db_user, :password => @configuration.db_password,
|
163
|
+
:host => @configuration.db_server, :database => @configuration.db_name, :port => @configuration.db_port
|
164
|
+
@database.query_options[:symbolize_keys] = true
|
165
|
+
rescue TinyTds::Error => e
|
166
|
+
throw_error("#{e}")
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
143
170
|
# Run a script against the currently configured database
|
144
171
|
def query_script(sql)
|
172
|
+
case @configuration.db_driver
|
173
|
+
when ODBC_DRIVER
|
174
|
+
query_script_odbc(sql)
|
175
|
+
when TINYTDS_DRIVER
|
176
|
+
query_script_tiny_tds(sql)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
def query_script_odbc(sql)
|
145
181
|
results = []
|
146
182
|
begin
|
147
183
|
st = @database.run(sql)
|
@@ -152,12 +188,22 @@ EOF
|
|
152
188
|
results << rows
|
153
189
|
end
|
154
190
|
end while(st.more_results)
|
155
|
-
|
156
|
-
|
191
|
+
ensure
|
192
|
+
st.drop unless st.nil?
|
157
193
|
end
|
158
194
|
results.count > 1 ? results : results.first
|
159
195
|
end
|
160
196
|
|
197
|
+
def query_script_tiny_tds(sql)
|
198
|
+
results = []
|
199
|
+
st = @database.execute(sql)
|
200
|
+
if st.fields
|
201
|
+
rows = st.each :as => :hash
|
202
|
+
results << rows
|
203
|
+
end
|
204
|
+
results.count > 1 ? results : results.first
|
205
|
+
end
|
206
|
+
|
161
207
|
# Customize RSpec
|
162
208
|
def configure_rspec
|
163
209
|
before_proc = lambda do |example|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Slacker
|
2
2
|
class Configuration
|
3
|
-
attr_accessor :base_dir, :error_stream, :output_stream, :formatter, :db_server, :db_name, :db_user, :db_password, :console_enabled
|
3
|
+
attr_accessor :base_dir, :error_stream, :output_stream, :formatter, :db_server, :db_name, :db_user, :db_password, :db_port, :db_driver, :console_enabled
|
4
4
|
|
5
5
|
def initialize
|
6
6
|
@console_enabled = true
|
@@ -13,6 +13,8 @@ module Slacker
|
|
13
13
|
@db_name = nil
|
14
14
|
@db_user = nil
|
15
15
|
@db_password = nil
|
16
|
+
@db_port = 1433
|
17
|
+
@db_driver = 'odbc'
|
16
18
|
end
|
17
19
|
|
18
20
|
def expand_path(path)
|
@@ -2,6 +2,7 @@ require 'csv'
|
|
2
2
|
|
3
3
|
module Slacker
|
4
4
|
DATE_FORMAT = "%m/%d/%Y"
|
5
|
+
DATETIME_FORMAT = '%Y-%m-%dT%H:%M:%S'
|
5
6
|
|
6
7
|
class QueryResultMatcher
|
7
8
|
def initialize(golden_master)
|
@@ -102,6 +103,10 @@ module Slacker
|
|
102
103
|
(!!Time.strptime(master_val, DATE_FORMAT) rescue false) && Time.strptime(master_val, DATE_FORMAT) == ODBC::to_time(subject_val)
|
103
104
|
when Float
|
104
105
|
(!!Float(master_val) rescue false) && Float(master_val) == subject_val
|
106
|
+
when BigDecimal
|
107
|
+
(!!BigDecimal(master_val) rescue false) && BigDecimal(master_val) == BigDecimal(subject_val)
|
108
|
+
when Time
|
109
|
+
(!!DateTime.strptime(DateTime.parse(master_val).to_s, DATETIME_FORMAT) rescue false) && DateTime.strptime(DateTime.parse(master_val).to_s, DATETIME_FORMAT) == DateTime.strptime(DateTime.parse(subject_val.to_s).to_s, DATETIME_FORMAT)
|
105
110
|
else
|
106
111
|
subject_val.to_s == master_val.to_s
|
107
112
|
end
|
data/lib/slacker/version.rb
CHANGED
@@ -3,7 +3,12 @@
|
|
3
3
|
|
4
4
|
# Replace the following with your connection information.
|
5
5
|
# Note that at this point Slacker only works with SQL Server authentication.
|
6
|
+
|
7
|
+
# Slacker supports odbc and tiny_tds drivers
|
8
|
+
|
6
9
|
server: my_server
|
7
10
|
database: my_database
|
8
11
|
user: user_name
|
9
12
|
password: password
|
13
|
+
port: 1433
|
14
|
+
driver: odbc #or tiny_tds
|
data/slacker.gemspec
CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.required_ruby_version = '>= 1.9.2'
|
23
23
|
|
24
24
|
s.add_dependency 'bundler', '~> 1.0', '>= 1.0.15'
|
25
|
-
s.add_dependency 'ruby-odbc', '= 0.
|
25
|
+
s.add_dependency 'ruby-odbc', '= 0.99998'
|
26
26
|
s.add_dependency 'rspec', '~> 3.0'
|
27
|
+
s.add_dependency 'tiny_tds', '~>2.0'
|
27
28
|
end
|
@@ -231,6 +231,17 @@ describe Slacker::QueryResultMatcher do
|
|
231
231
|
it_behaves_like 'single-value-based matcher'
|
232
232
|
end
|
233
233
|
|
234
|
+
describe 'BigDecimal point-based golden master' do
|
235
|
+
before(:each) do
|
236
|
+
@subject = [{'Field 1' => -3.12e-5, 'Field_2' => 12}]
|
237
|
+
@correct_golden_master = -0.0000312
|
238
|
+
@wrong_value_golden_master = -0.0000317
|
239
|
+
@wrong_type_golden_master = 15
|
240
|
+
end
|
241
|
+
|
242
|
+
it_behaves_like 'single-value-based matcher'
|
243
|
+
end
|
244
|
+
|
234
245
|
describe 'Date-based golden master' do
|
235
246
|
before(:each) do
|
236
247
|
@subject = [{'Field 1' => Time.parse('1/1/2011'), 'Field_2' => 12}]
|
@@ -242,6 +253,19 @@ describe Slacker::QueryResultMatcher do
|
|
242
253
|
it_behaves_like 'single-value-based matcher'
|
243
254
|
end
|
244
255
|
|
256
|
+
describe 'DateTime2-based golden master' do
|
257
|
+
before(:each) do
|
258
|
+
@subject = [{'Field 1' => Time.parse('2017-01-01.000000'), 'Field_2' => 12}]
|
259
|
+
@correct_golden_master = Time.parse('2017-01-01 00:00:00')
|
260
|
+
@wrong_value_golden_master = Time.parse('2017-02-01.000000')
|
261
|
+
@wrong_type_golden_master = 'whatever'
|
262
|
+
end
|
263
|
+
|
264
|
+
it_behaves_like 'single-value-based matcher'
|
265
|
+
end
|
266
|
+
|
267
|
+
|
268
|
+
|
245
269
|
describe 'Nil-based golden master' do
|
246
270
|
before(:each) do
|
247
271
|
@subject = [{'Field 1' => nil, 'Field_2' => 12}]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slacker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vassil Kovatchev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -36,14 +36,14 @@ dependencies:
|
|
36
36
|
requirements:
|
37
37
|
- - '='
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: '0.
|
39
|
+
version: '0.99998'
|
40
40
|
type: :runtime
|
41
41
|
prerelease: false
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
44
|
- - '='
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: '0.
|
46
|
+
version: '0.99998'
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,6 +58,20 @@ dependencies:
|
|
58
58
|
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '3.0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: tiny_tds
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '2.0'
|
68
|
+
type: :runtime
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '2.0'
|
61
75
|
description: RSpec-based framework for developing automated tests for SQL Server
|
62
76
|
email:
|
63
77
|
- vassil.kovatchev@gmail.com
|
@@ -144,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
158
|
version: '0'
|
145
159
|
requirements: []
|
146
160
|
rubyforge_project: slacker
|
147
|
-
rubygems_version: 2.
|
161
|
+
rubygems_version: 2.5.2
|
148
162
|
signing_key:
|
149
163
|
specification_version: 4
|
150
164
|
summary: Behavior Driven Development for SQL Server
|