1
1
WINDOWS = Gem . win_platform? || ( JRUBY && ENV_JAVA [ 'os.name' ] =~ /windows/i )
2
2
3
- share_examples_for 'a Command' do
3
+ shared 'a Command' do
4
4
5
- include DataObjectsSpecHelpers
5
+ setup_test_environment
6
6
7
- before :all do
8
- setup_test_environment
9
- end
10
-
11
- before :each do
7
+ before do
12
8
@connection = DataObjects ::Connection . new ( CONFIG . uri )
13
9
@command = @connection . create_command ( "INSERT INTO users (name) VALUES (?)" )
14
10
@reader = @connection . create_command ( "SELECT code, name FROM widgets WHERE ad_description = ?" )
15
11
end
16
12
17
- after :each do
13
+ after do
18
14
@connection . close
19
15
end
20
16
21
- it { @command . should be_kind_of ( DataObjects ::Command ) }
17
+ it 'should be a kind of Command' do @command . should . be . kind_of ( DataObjects ::Command ) end
22
18
23
- it { @command . should respond_to ( :execute_non_query ) }
19
+ it 'should respond to #execute_non_query' do @command . should . respond_to ( :execute_non_query ) end
24
20
25
21
describe 'execute_non_query' do
26
22
27
23
describe 'with an invalid statement' do
28
24
29
- before :each do
25
+ before do
30
26
@invalid_command = @connection . create_command ( "INSERT INTO non_existent_table (tester) VALUES (1)" )
31
27
end
32
28
33
29
it 'should raise an error on an invalid query' do
34
- lambda { @invalid_command . execute_non_query } . should raise_error
30
+ lambda { @invalid_command . execute_non_query } . should . raise ( DataObjects :: Error ) # FIXME JRuby: DataObjects::SQLError
35
31
end
36
32
37
33
it 'should raise an error with too few binding parameters' do
38
- lambda { @command . execute_non_query ( "Too" , "Many" ) } . should raise_error ( ArgumentError , "Binding mismatch: 2 for 1" )
34
+ lambda { @command . execute_non_query ( "Too" , "Many" ) } . should . raise ( ArgumentError , "Binding mismatch: 2 for 1" )
39
35
end
40
36
41
37
it 'should raise an error with too many binding parameters' do
42
- lambda { @command . execute_non_query } . should raise_error ( ArgumentError , "Binding mismatch: 0 for 1" )
38
+ lambda { @command . execute_non_query } . should . raise ( ArgumentError , "Binding mismatch: 0 for 1" )
43
39
end
44
40
45
41
end
46
42
47
43
describe 'with a valid statement' do
48
44
49
45
it 'should not raise an error with an explicit nil as parameter' do
50
- lambda { @command . execute_non_query ( nil ) } . should_not raise_error
46
+ lambda { @command . execute_non_query ( nil ) } . should . not . raise
51
47
end
52
48
53
49
end
54
50
55
51
describe 'with a valid statement and ? inside quotes' do
56
52
57
- before :each do
53
+ before do
58
54
@command_with_quotes = @connection . create_command ( "INSERT INTO users (name) VALUES ('will it work? ')" )
59
55
end
60
56
61
57
it 'should not raise an error' do
62
- lambda { @command_with_quotes . execute_non_query } . should_not raise_error
58
+ lambda { @command_with_quotes . execute_non_query } . should . not . raise
63
59
end
64
60
65
61
end
66
62
67
63
end
68
64
69
- it { @command . should respond_to ( :execute_reader ) }
65
+ it 'should respond to #execute_reader' do @command . should . respond_to ( :execute_reader ) end
70
66
71
67
describe 'execute_reader' do
72
68
73
69
describe 'with an invalid reader' do
74
70
75
- before :each do
71
+ before do
76
72
@invalid_reader = @connection . create_command ( "SELECT * FROM non_existent_widgets WHERE ad_description = ?" )
77
73
end
78
74
79
75
it 'should raise an error on an invalid query' do
80
- lambda { @invalid_reader . execute_reader } . should raise_error
76
+ # FIXME JRuby (and MRI): Should this be an argument errror or DataObjects::SQLError?
77
+ lambda { @invalid_reader . execute_reader } . should . raise ( ArgumentError , DataObjects ::Error )
81
78
end
82
79
83
80
it 'should raise an error with too few binding parameters' do
84
- lambda { @reader . execute_reader ( "Too" , "Many" ) } . should raise_error ( ArgumentError , "Binding mismatch: 2 for 1" )
81
+ lambda { @reader . execute_reader ( "Too" , "Many" ) } . should . raise ( ArgumentError , "Binding mismatch: 2 for 1" )
85
82
end
86
83
87
84
it 'should raise an error with too many binding parameters' do
88
- lambda { @reader . execute_reader } . should raise_error ( ArgumentError , "Binding mismatch: 0 for 1" )
85
+ lambda { @reader . execute_reader } . should . raise ( ArgumentError , "Binding mismatch: 0 for 1" )
89
86
end
90
87
91
88
end
92
89
93
90
describe 'with a valid reader' do
94
91
95
92
it 'should not raise an error with an explicit nil as parameter' do
96
- lambda { @reader . execute_reader ( nil ) } . should_not raise_error
93
+ lambda { @reader . execute_reader ( nil ) } . should . not . raise
97
94
end
98
95
99
96
end
100
97
101
98
describe 'with a valid reader and ? inside column alias' do
102
99
103
- before :each do
100
+ before do
104
101
@reader_with_quotes = @connection . create_command ( "SELECT code AS \" code?\" , name FROM widgets WHERE ad_description = ?" )
105
102
end
106
103
107
104
it 'should not raise an error' do
108
- lambda { @reader_with_quotes . execute_reader ( nil ) } . should_not raise_error
105
+ lambda { @reader_with_quotes . execute_reader ( nil ) } . should . not . raise
109
106
end
110
107
111
108
end
112
109
113
110
114
111
end
115
112
116
- it { @command . should respond_to ( :set_types ) }
113
+ it 'should respond to #set_types' do @command . should . respond_to ( :set_types ) end
117
114
118
115
describe 'set_types' do
119
116
120
117
describe 'is invalid when used with a statement' do
121
118
122
- before :each do
119
+ before do
123
120
@command . set_types ( String )
124
121
end
125
122
126
123
it 'should raise an error when types are set' do
127
- lambda { @command . execute_non_query } . should raise_error
124
+ lambda { @command . execute_non_query } . should . raise ( ArgumentError )
128
125
end
129
126
130
127
end
133
130
134
131
it 'should raise an error with too few types' do
135
132
@reader . set_types ( String )
136
- lambda { @reader . execute_reader ( "One parameter" ) } . should raise_error ( ArgumentError , "Field-count mismatch. Expected 1 fields, but the query yielded 2" )
133
+ lambda { @reader . execute_reader ( "One parameter" ) } . should . raise ( ArgumentError , "Field-count mismatch. Expected 1 fields, but the query yielded 2" )
137
134
end
138
135
139
136
it 'should raise an error with too many types' do
140
137
@reader . set_types ( String , String , BigDecimal )
141
- lambda { @reader . execute_reader ( "One parameter" ) } . should raise_error ( ArgumentError , "Field-count mismatch. Expected 3 fields, but the query yielded 2" )
138
+ lambda { @reader . execute_reader ( "One parameter" ) } . should . raise ( ArgumentError , "Field-count mismatch. Expected 3 fields, but the query yielded 2" )
142
139
end
143
140
144
141
end
147
144
148
145
it 'should not raise an error with correct number of types' do
149
146
@reader . set_types ( String , String )
150
- lambda { @result = @reader . execute_reader ( 'Buy this product now!' ) } . should_not raise_error
151
- lambda { @result . next! } . should_not raise_error
152
- lambda { @result . values } . should_not raise_error
147
+ lambda { @result = @reader . execute_reader ( 'Buy this product now!' ) } . should . not . raise
148
+ lambda { @result . next! } . should . not . raise
149
+ lambda { @result . values } . should . not . raise
153
150
@result . close
154
151
end
155
152
156
153
it 'should also support old style array argument types' do
157
154
@reader . set_types ( [ String , String ] )
158
- lambda { @result = @reader . execute_reader ( 'Buy this product now!' ) } . should_not raise_error
159
- lambda { @result . next! } . should_not raise_error
160
- lambda { @result . values } . should_not raise_error
155
+ lambda { @result = @reader . execute_reader ( 'Buy this product now!' ) } . should . not . raise
156
+ lambda { @result . next! } . should . not . raise
157
+ lambda { @result . values } . should . not . raise
161
158
@result . close
162
159
end
163
160
164
161
it 'should allow subtype types' do
165
162
class MyString < String ; end
166
163
@reader . set_types ( MyString , String )
167
- lambda { @result = @reader . execute_reader ( 'Buy this product now!' ) } . should_not raise_error
168
- lambda { @result . next! } . should_not raise_error
169
- lambda { @result . values } . should_not raise_error
164
+ lambda { @result = @reader . execute_reader ( 'Buy this product now!' ) } . should . not . raise
165
+ lambda { @result . next! } . should . not . raise
166
+ lambda { @result . values } . should . not . raise
170
167
@result . close
171
168
end
172
169
end
173
170
174
171
end
175
172
176
- it { @command . should respond_to ( :to_s ) }
173
+ it 'should respond to #to_s' do @command . should . respond_to ( :to_s ) end
177
174
178
175
describe 'to_s' do
179
176
@@ -182,17 +179,13 @@ class MyString < String; end
182
179
183
180
end
184
181
185
- share_examples_for 'a Command with async' do
182
+ shared 'a Command with async' do
186
183
187
- include DataObjectsSpecHelpers
188
-
189
- before :all do
190
- setup_test_environment
191
- end
184
+ setup_test_environment
192
185
193
186
describe 'running queries in parallel' do
194
187
195
- before :each do
188
+ before do
196
189
197
190
threads = [ ]
198
191
@@ -216,7 +209,7 @@ class MyString < String; end
216
209
@finish = Time . now
217
210
end
218
211
219
- after :each do
212
+ after do
220
213
@connection . close
221
214
end
222
215
0 commit comments