dbexpect 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/.document +5 -0
  2. data/.rspec +1 -0
  3. data/.rvmrc +41 -0
  4. data/COPYING +674 -0
  5. data/Gemfile +20 -0
  6. data/Gemfile.lock +45 -0
  7. data/LICENSE.txt +2 -0
  8. data/README.md +106 -0
  9. data/Rakefile +65 -0
  10. data/VERSION +1 -0
  11. data/bin/dbexpect +33 -0
  12. data/bin/great-expectations +28 -0
  13. data/bin/ready-rig +27 -0
  14. data/database.yml +9 -0
  15. data/lib/dbexpect.rb +19 -0
  16. data/lib/dbexpect/command_runner.rb +21 -0
  17. data/lib/dbexpect/console_formatter.rb +40 -0
  18. data/lib/dbexpect/d_s_l_parser.rb +124 -0
  19. data/lib/dbexpect/database.rb +59 -0
  20. data/lib/dbexpect/db_null.rb +25 -0
  21. data/lib/dbexpect/db_sequence.rb +26 -0
  22. data/lib/dbexpect/db_string.rb +29 -0
  23. data/lib/dbexpect/dbexpect.rb +87 -0
  24. data/lib/dbexpect/defaulting_row_set.rb +68 -0
  25. data/lib/dbexpect/expectation_checker.rb +32 -0
  26. data/lib/dbexpect/expectation_tree_node.rb +67 -0
  27. data/lib/dbexpect/expectations/expectation.rb +45 -0
  28. data/lib/dbexpect/expectations/row_count_expectation.rb +32 -0
  29. data/lib/dbexpect/expectations/row_expectation.rb +32 -0
  30. data/lib/dbexpect/odbc_connection.rb +47 -0
  31. data/lib/dbexpect/row.rb +43 -0
  32. data/lib/dbexpect/table.rb +71 -0
  33. data/spec/dbexpect_integration_spec.rb +131 -0
  34. data/spec/defaulting_row_set_spec.rb +37 -0
  35. data/spec/expectation_checker_spec.rb +47 -0
  36. data/spec/expectations/row_expectation_spec.rb +51 -0
  37. data/spec/fixtures/basic_test_expected_inserts.sql +6 -0
  38. data/spec/fixtures/cleanup_db.sql +2 -0
  39. data/spec/fixtures/expected_output.txt +11 -0
  40. data/spec/fixtures/sample_db.sql +12 -0
  41. data/spec/fixtures/sample_project/database.yml +9 -0
  42. data/spec/fixtures/sample_project/defaults/defaults.rb +5 -0
  43. data/spec/fixtures/sample_project/tests/basic_test.rb +41 -0
  44. data/spec/fixtures/sample_project/tests/test2.rb +3 -0
  45. data/spec/spec_helper.rb +28 -0
  46. metadata +186 -0
@@ -0,0 +1,51 @@
1
+ # Copyright 2012 C3 Business Solutions
2
+ #
3
+ # This file is part of dbexpect.
4
+ #
5
+ # dbexpect is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # dbexpect is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with dbexpect. If not, see <http://www.gnu.org/licenses/>.
17
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
18
+
19
+ describe RowExpectation do
20
+ describe "validating expectations against the database" do
21
+ def stub_row(where_clause)
22
+ mock(:where_clause => where_clause)
23
+ end
24
+
25
+ before :each do
26
+ @db = {:dbname => mock}
27
+ @expected_row = stub_row('clause1')
28
+
29
+ @it = RowExpectation.new(:dbname,'schema','tablename',@expected_row)
30
+ end
31
+
32
+
33
+ it "should gather failure messages for failed expectations" do
34
+ @db[:dbname].should_receive(:num_rows_match).with('schema','tablename','clause1').
35
+ and_return(2)
36
+
37
+ @it.validate_expectation(@db)
38
+ @it.failed_validation?.should be_true
39
+ @it.failure_message.should == "Expected schema.tablename to contain a row where clause1, got 2"
40
+ end
41
+
42
+ it "should gather failure messages for exception-causing" do
43
+ @db[:dbname].should_receive(:num_rows_match).with('schema','tablename','clause1').
44
+ and_raise(OdbcConnection::DatabaseException.new('error message'))
45
+
46
+ @it.validate_expectation(@db)
47
+ @it.failed_validation?.should be_true
48
+ @it.failure_message.should == "Expected schema.tablename to contain a row where clause1, instead database raised error: error message"
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,6 @@
1
+ insert into target.tgt_table (str_column,int_column,nullable_col) VALUES
2
+ ('defaulted in script',1,null),
3
+ ('defaulted in script',2,null),
4
+ ('defaulted in script',3,null),
5
+ ('defaulted in script',4,4),
6
+ ('special row',5,6);
@@ -0,0 +1,2 @@
1
+ drop schema source cascade;
2
+ drop schema target cascade;
@@ -0,0 +1,11 @@
1
+ ->:
2
+ our basic test definition test:
3
+ Expected target.tgt_table to contain 5 rows, got 0
4
+ test case 1:
5
+ Expected target.tgt_table to contain a row where str_column = 'defaulted in script' AND int_column = '1' AND nullable_col is null, got 0
6
+ Expected target.tgt_table to contain a row where str_column = 'defaulted in script' AND int_column = '2' AND nullable_col is null, got 0
7
+ Expected target.tgt_table to contain a row where str_column = 'defaulted in script' AND int_column = '3' AND nullable_col is null, got 0
8
+ Expected target.tgt_table to contain a row where str_column = 'defaulted in script' AND int_column = '4' AND nullable_col = '4', got 0
9
+ nested definition:
10
+ Expected target.tgt_table to contain a row where str_column = 'special row' AND int_column = '5' AND nullable_col = '6', got 0
11
+ Failed to meet expectations
@@ -0,0 +1,12 @@
1
+ create schema source;
2
+ create schema target;
3
+
4
+ create table source.src_table (
5
+ str_column varchar(255),
6
+ int_column integer,
7
+ nullable_col varchar(255) null);
8
+
9
+ create table target.tgt_table (
10
+ str_column varchar(255),
11
+ int_column integer,
12
+ nullable_col integer null );
@@ -0,0 +1,9 @@
1
+ dbexpect_src:
2
+ database: testgen_src
3
+ username: dbexpect
4
+ password: dbexpect
5
+
6
+ dbexpect_tgt:
7
+ database: testgen_tgt
8
+ username: dbexpect
9
+ password: dbexpect
@@ -0,0 +1,5 @@
1
+ @src = table(:dbexpect_src,:source,:src_table)
2
+
3
+ defaults_for @src,
4
+ :str_column => "default string",
5
+ :nullable_col => NULL
@@ -0,0 +1,41 @@
1
+ requires 'spec/fixtures/sample_project/defaults/defaults.rb'
2
+
3
+ describe "our basic test definition test" do
4
+ @src = table(:dbexpect_src,:source,:src_table)
5
+ @tgt = table(:dbexpect_tgt,:target,:tgt_table)
6
+
7
+ etl_run_command "echo 400"
8
+
9
+ expected_defaults @tgt,
10
+ :str_column => 'defaulted in script',
11
+ :int_column => 5
12
+
13
+ expect_total_rows @tgt, 5
14
+
15
+ describe "test case 1" do
16
+ insert_into @src,
17
+ [:int_column],
18
+ [[7]]
19
+
20
+ expect_rows @tgt,
21
+ [:int_column,:nullable_col],
22
+ [
23
+ [1,NULL],
24
+ [2,nil],
25
+ [3,null],
26
+ [4,4] ]
27
+ end
28
+
29
+ describe "nested definition" do
30
+ insert_into @src,
31
+ [:str_column,:int_column,:nullable_col],
32
+ [
33
+ ['overridden string',1,'not null'] ]
34
+
35
+ expect_rows @tgt,
36
+ [:str_column,:nullable_col],
37
+ [
38
+ ['special row',6]]
39
+ end
40
+
41
+ end
@@ -0,0 +1,3 @@
1
+ @src = table(:dbexpect_src,:source, :src_table)
2
+ defaults_for @src,
3
+ :test_script2_col => "blah"
@@ -0,0 +1,28 @@
1
+ # Copyright 2012 C3 Business Solutions
2
+ #
3
+ # This file is part of dbexpect.
4
+ #
5
+ # dbexpect is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # dbexpect is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with dbexpect. If not, see <http://www.gnu.org/licenses/>.
17
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
18
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
19
+ require 'rspec'
20
+ require 'dbexpect'
21
+
22
+ # Requires supporting files with custom matchers and macros, etc,
23
+ # in ./support/ and its subdirectories.
24
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
25
+
26
+ RSpec.configure do |config|
27
+
28
+ end
metadata ADDED
@@ -0,0 +1,186 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dbexpect
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.11.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Beau Fabry
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: ruby-odbc
16
+ requirement: &18938120 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *18938120
25
+ - !ruby/object:Gem::Dependency
26
+ name: rdoc
27
+ requirement: &18952680 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '3.12'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *18952680
36
+ - !ruby/object:Gem::Dependency
37
+ name: bundler
38
+ requirement: &18951800 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *18951800
47
+ - !ruby/object:Gem::Dependency
48
+ name: jeweler
49
+ requirement: &18950800 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.8.3
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *18950800
58
+ - !ruby/object:Gem::Dependency
59
+ name: rspec
60
+ requirement: &18949940 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: 2.8.0
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *18949940
69
+ - !ruby/object:Gem::Dependency
70
+ name: pg
71
+ requirement: &18948480 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *18948480
80
+ - !ruby/object:Gem::Dependency
81
+ name: pry
82
+ requirement: &18947260 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *18947260
91
+ - !ruby/object:Gem::Dependency
92
+ name: ZenTest
93
+ requirement: &18962060 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *18962060
102
+ description: As above
103
+ email: beau.fabry@c3businesssolutions.com
104
+ executables:
105
+ - dbexpect
106
+ - great-expectations
107
+ - ready-rig
108
+ extensions: []
109
+ extra_rdoc_files:
110
+ - LICENSE.txt
111
+ - README.md
112
+ files:
113
+ - .document
114
+ - .rspec
115
+ - .rvmrc
116
+ - COPYING
117
+ - Gemfile
118
+ - Gemfile.lock
119
+ - LICENSE.txt
120
+ - README.md
121
+ - Rakefile
122
+ - VERSION
123
+ - bin/dbexpect
124
+ - bin/great-expectations
125
+ - bin/ready-rig
126
+ - database.yml
127
+ - lib/dbexpect.rb
128
+ - lib/dbexpect/command_runner.rb
129
+ - lib/dbexpect/console_formatter.rb
130
+ - lib/dbexpect/d_s_l_parser.rb
131
+ - lib/dbexpect/database.rb
132
+ - lib/dbexpect/db_null.rb
133
+ - lib/dbexpect/db_sequence.rb
134
+ - lib/dbexpect/db_string.rb
135
+ - lib/dbexpect/dbexpect.rb
136
+ - lib/dbexpect/defaulting_row_set.rb
137
+ - lib/dbexpect/expectation_checker.rb
138
+ - lib/dbexpect/expectation_tree_node.rb
139
+ - lib/dbexpect/expectations/expectation.rb
140
+ - lib/dbexpect/expectations/row_count_expectation.rb
141
+ - lib/dbexpect/expectations/row_expectation.rb
142
+ - lib/dbexpect/odbc_connection.rb
143
+ - lib/dbexpect/row.rb
144
+ - lib/dbexpect/table.rb
145
+ - spec/dbexpect_integration_spec.rb
146
+ - spec/defaulting_row_set_spec.rb
147
+ - spec/expectation_checker_spec.rb
148
+ - spec/expectations/row_expectation_spec.rb
149
+ - spec/fixtures/basic_test_expected_inserts.sql
150
+ - spec/fixtures/cleanup_db.sql
151
+ - spec/fixtures/expected_output.txt
152
+ - spec/fixtures/sample_db.sql
153
+ - spec/fixtures/sample_project/database.yml
154
+ - spec/fixtures/sample_project/defaults/defaults.rb
155
+ - spec/fixtures/sample_project/tests/basic_test.rb
156
+ - spec/fixtures/sample_project/tests/test2.rb
157
+ - spec/spec_helper.rb
158
+ homepage: http://github.com/bfabry/dbexpect
159
+ licenses:
160
+ - PRIVATE
161
+ post_install_message:
162
+ rdoc_options: []
163
+ require_paths:
164
+ - lib
165
+ required_ruby_version: !ruby/object:Gem::Requirement
166
+ none: false
167
+ requirements:
168
+ - - ! '>='
169
+ - !ruby/object:Gem::Version
170
+ version: '0'
171
+ segments:
172
+ - 0
173
+ hash: 4552705897019438332
174
+ required_rubygems_version: !ruby/object:Gem::Requirement
175
+ none: false
176
+ requirements:
177
+ - - ! '>='
178
+ - !ruby/object:Gem::Version
179
+ version: '0'
180
+ requirements: []
181
+ rubyforge_project:
182
+ rubygems_version: 1.8.11
183
+ signing_key:
184
+ specification_version: 3
185
+ summary: Generates inserts for test data from DSL
186
+ test_files: []