Skip to content
This repository was archived by the owner on Apr 17, 2018. It is now read-only.

Commit 9d9d4cc

Browse files
committed
[all] Port shared, driver specs to Bacon
Signed-off-by: Alex Coles <alex@alexcolesportfolio.com>
1 parent 355b302 commit 9d9d4cc

File tree

179 files changed

+826
-935
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

179 files changed

+826
-935
lines changed

data_objects/lib/data_objects/spec/command_spec.rb

+41-48
Original file line numberDiff line numberDiff line change
@@ -1,130 +1,127 @@
11
WINDOWS = Gem.win_platform? || (JRUBY && ENV_JAVA['os.name'] =~ /windows/i)
22

3-
share_examples_for 'a Command' do
3+
shared 'a Command' do
44

5-
include DataObjectsSpecHelpers
5+
setup_test_environment
66

7-
before :all do
8-
setup_test_environment
9-
end
10-
11-
before :each do
7+
before do
128
@connection = DataObjects::Connection.new(CONFIG.uri)
139
@command = @connection.create_command("INSERT INTO users (name) VALUES (?)")
1410
@reader = @connection.create_command("SELECT code, name FROM widgets WHERE ad_description = ?")
1511
end
1612

17-
after :each do
13+
after do
1814
@connection.close
1915
end
2016

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
2218

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
2420

2521
describe 'execute_non_query' do
2622

2723
describe 'with an invalid statement' do
2824

29-
before :each do
25+
before do
3026
@invalid_command = @connection.create_command("INSERT INTO non_existent_table (tester) VALUES (1)")
3127
end
3228

3329
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
3531
end
3632

3733
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")
3935
end
4036

4137
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")
4339
end
4440

4541
end
4642

4743
describe 'with a valid statement' do
4844

4945
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
5147
end
5248

5349
end
5450

5551
describe 'with a valid statement and ? inside quotes' do
5652

57-
before :each do
53+
before do
5854
@command_with_quotes = @connection.create_command("INSERT INTO users (name) VALUES ('will it work? ')")
5955
end
6056

6157
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
6359
end
6460

6561
end
6662

6763
end
6864

69-
it { @command.should respond_to(:execute_reader) }
65+
it 'should respond to #execute_reader' do @command.should.respond_to(:execute_reader) end
7066

7167
describe 'execute_reader' do
7268

7369
describe 'with an invalid reader' do
7470

75-
before :each do
71+
before do
7672
@invalid_reader = @connection.create_command("SELECT * FROM non_existent_widgets WHERE ad_description = ?")
7773
end
7874

7975
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)
8178
end
8279

8380
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")
8582
end
8683

8784
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")
8986
end
9087

9188
end
9289

9390
describe 'with a valid reader' do
9491

9592
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
9794
end
9895

9996
end
10097

10198
describe 'with a valid reader and ? inside column alias' do
10299

103-
before :each do
100+
before do
104101
@reader_with_quotes = @connection.create_command("SELECT code AS \"code?\", name FROM widgets WHERE ad_description = ?")
105102
end
106103

107104
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
109106
end
110107

111108
end
112109

113110

114111
end
115112

116-
it { @command.should respond_to(:set_types) }
113+
it 'should respond to #set_types' do @command.should.respond_to(:set_types) end
117114

118115
describe 'set_types' do
119116

120117
describe 'is invalid when used with a statement' do
121118

122-
before :each do
119+
before do
123120
@command.set_types(String)
124121
end
125122

126123
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)
128125
end
129126

130127
end
@@ -133,12 +130,12 @@
133130

134131
it 'should raise an error with too few types' do
135132
@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")
137134
end
138135

139136
it 'should raise an error with too many types' do
140137
@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")
142139
end
143140

144141
end
@@ -147,33 +144,33 @@
147144

148145
it 'should not raise an error with correct number of types' do
149146
@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
153150
@result.close
154151
end
155152

156153
it 'should also support old style array argument types' do
157154
@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
161158
@result.close
162159
end
163160

164161
it 'should allow subtype types' do
165162
class MyString < String; end
166163
@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
170167
@result.close
171168
end
172169
end
173170

174171
end
175172

176-
it { @command.should respond_to(:to_s) }
173+
it 'should respond to #to_s' do @command.should.respond_to(:to_s) end
177174

178175
describe 'to_s' do
179176

@@ -182,17 +179,13 @@ class MyString < String; end
182179

183180
end
184181

185-
share_examples_for 'a Command with async' do
182+
shared 'a Command with async' do
186183

187-
include DataObjectsSpecHelpers
188-
189-
before :all do
190-
setup_test_environment
191-
end
184+
setup_test_environment
192185

193186
describe 'running queries in parallel' do
194187

195-
before :each do
188+
before do
196189

197190
threads = []
198191

@@ -216,7 +209,7 @@ class MyString < String; end
216209
@finish = Time.now
217210
end
218211

219-
after :each do
212+
after do
220213
@connection.close
221214
end
222215

0 commit comments

Comments
 (0)