Skip to content

Commit 9c22bb0

Browse files
committed
Migrate legacy "should" to "expect"
1 parent 7354526 commit 9c22bb0

File tree

3 files changed

+78
-76
lines changed

3 files changed

+78
-76
lines changed

Diff for: spec/client_spec.rb

+16-16
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,23 @@
2222

2323
rehashed = client.run_with_names('fake query')
2424

25-
rehashed.length.should == 3
25+
expect(rehashed.length).to eq 3
2626

27-
rehashed[0]['animal'].should == 'dog'
28-
rehashed[0]['score'].should == 1
29-
rehashed[0]['name'].should == 'Lassie'
27+
expect(rehashed[0]['animal']).to eq 'dog'
28+
expect(rehashed[0]['score']).to eq 1
29+
expect(rehashed[0]['name']).to eq 'Lassie'
3030

31-
rehashed[0].values[0].should == 'dog'
32-
rehashed[0].values[1].should == 1
33-
rehashed[0].values[2].should == 'Lassie'
31+
expect(rehashed[0].values[0]).to eq 'dog'
32+
expect(rehashed[0].values[1]).to eq 1
33+
expect(rehashed[0].values[2]).to eq 'Lassie'
3434

35-
rehashed[1]['animal'].should == 'horse'
36-
rehashed[1]['score'].should == 5
37-
rehashed[1]['name'].should == 'Mr. Ed'
35+
expect(rehashed[1]['animal']).to eq 'horse'
36+
expect(rehashed[1]['score']).to eq 5
37+
expect(rehashed[1]['name']).to eq 'Mr. Ed'
3838

39-
rehashed[1].values[0].should == 'horse'
40-
rehashed[1].values[1].should == 5
41-
rehashed[1].values[2].should == 'Mr. Ed'
39+
expect(rehashed[1].values[0]).to eq 'horse'
40+
expect(rehashed[1].values[1]).to eq 5
41+
expect(rehashed[1].values[2]).to eq 'Mr. Ed'
4242
end
4343

4444
it 'empty results' do
@@ -47,14 +47,14 @@
4747

4848
rehashed = client.run_with_names('fake query')
4949

50-
rehashed.length.should == 0
50+
expect(rehashed.length).to eq 0
5151
end
5252

5353
it 'handles too few result columns' do
5454
rows = [['wrong', 'count']]
5555
client.stub(:run).and_return([columns, rows])
5656

57-
client.run_with_names('fake query').should == [{
57+
expect(client.run_with_names('fake query')).to eq [{
5858
"animal" => "wrong",
5959
"score" => "count",
6060
"name" => nil,
@@ -65,7 +65,7 @@
6565
rows = [['wrong', 'count', 'too', 'much', 'columns']]
6666
client.stub(:run).and_return([columns, rows])
6767

68-
client.run_with_names('fake query').should == [{
68+
expect(client.run_with_names('fake query')).to eq [{
6969
"animal" => "wrong",
7070
"score" => "count",
7171
"name" => 'too',

Diff for: spec/model_spec.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
"info" => {"k" => "v"}
3030
}
3131

32-
stats = Models::OperatorStats.decode(h)
33-
stats.blocked_reason.should == :waiting_for_memory
32+
it 'decode blocked_reason' do
33+
stats = Models::OperatorStats.decode(h)
34+
expect(stats.blocked_reason).to eq :waiting_for_memory
35+
end
3436
end
3537
end

Diff for: spec/statement_client_spec.rb

+58-58
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@
7676
}).to_return(body: lambda { |req| if retry_p; response_json.to_json; else; retry_p = true; raise Timeout::Error.new("execution expired"); end })
7777

7878
sc = StatementClient.new(faraday, query, options.merge(http_open_timeout: 1))
79-
sc.has_next?.should be_true
80-
sc.advance.should be_true
81-
retry_p.should be_true
79+
expect(sc.has_next?).to eq true
80+
expect(sc.advance).to eq true
81+
expect(retry_p).to eq true
8282
end
8383

8484
it "uses 'Accept: application/x-msgpack' if option is set" do
@@ -108,9 +108,9 @@
108108

109109
options.merge!(http_open_timeout: 1, enable_x_msgpack: "application/x-msgpack")
110110
sc = StatementClient.new(faraday, query, options)
111-
sc.has_next?.should be_true
112-
sc.advance.should be_true
113-
retry_p.should be_true
111+
expect(sc.has_next?).to eq true
112+
expect(sc.advance).to eq true
113+
expect(retry_p).to eq true
114114
end
115115

116116
# trino version could be "V0_ddd" or "Vddd"
@@ -127,17 +127,17 @@
127127
"connectorHandle" => {}
128128
}
129129
})
130-
dh.handle.should be_a_kind_of Models::TableHandle
131-
dh.handle.connector_id.should == "c1"
132-
dh.handle.connector_handle.should == {}
130+
expect(dh.handle).to be_a_kind_of Models::TableHandle
131+
expect(dh.handle.connector_id).to eq "c1"
132+
expect(dh.handle.connector_handle).to eq {}
133133
end
134134

135135
it "validates models" do
136-
lambda do
136+
expect do
137137
Models::DeleteHandle.decode({
138138
"handle" => "invalid"
139139
})
140-
end.should raise_error(TypeError, /String to Hash/)
140+
end.to raise_error(TypeError, /String to Hash/)
141141
end
142142
else
143143
it "decodes DeleteTarget" do
@@ -147,18 +147,18 @@
147147
"connectorHandle" => {}
148148
}
149149
})
150-
dh.handle.should be_a_kind_of Models::TableHandle
151-
dh.handle.catalog_name.should == "c1"
152-
dh.handle.connector_handle.should == {}
150+
expect(dh.handle).to be_a_kind_of(Models::TableHandle)
151+
expect(dh.handle.catalog_name).to eq "c1"
152+
expect(dh.handle.connector_handle).to eq({})
153153
end
154154

155155
it "validates models" do
156-
lambda do
156+
expect do
157157
Models::DeleteTarget.decode({
158158
"catalogName" => "c1",
159159
"handle" => "invalid"
160160
})
161-
end.should raise_error(TypeError, /String to Hash/)
161+
end.to raise_error(TypeError, /String to Hash/)
162162
end
163163
end
164164

@@ -167,15 +167,15 @@
167167
with(body: query).to_return(body: response_json2.to_json, headers: {"X-Test-Header" => "123"})
168168

169169
sc = StatementClient.new(faraday, query, options.merge(http_open_timeout: 1))
170-
sc.current_results_headers["X-Test-Header"].should == "123"
170+
expect(sc.current_results_headers["X-Test-Header"]).to eq "123"
171171
end
172172

173173
it "receives headers of POST through Query" do
174174
stub_request(:post, "localhost/v1/statement").
175175
with(body: query).to_return(body: response_json2.to_json, headers: {"X-Test-Header" => "123"})
176176

177177
q = Trino::Client.new(options).query(query)
178-
q.current_results_headers["X-Test-Header"].should == "123"
178+
expect(q.current_results_headers["X-Test-Header"]).to eq "123"
179179
end
180180

181181
describe "#query_id" do
@@ -187,10 +187,10 @@
187187
to_return(body: response_json.to_json, headers: {"X-Test-Header" => "123"})
188188

189189
sc = StatementClient.new(faraday, query, options.merge(http_open_timeout: 1))
190-
sc.query_id.should == "queryid"
191-
sc.has_next?.should be_true
192-
sc.advance.should be_true
193-
sc.query_id.should == "queryid"
190+
expect(sc.query_id).to eq "queryid"
191+
expect(sc.has_next?).to eq true
192+
expect(sc.advance).to eq true
193+
expect(sc.query_id).to eq "queryid"
194194
end
195195
end
196196

@@ -214,21 +214,21 @@
214214
end
215215

216216
it "raises an exception with sample JSON if response is unexpected" do
217-
lambda do
217+
expect do
218218
stub_request(:get, "http://localhost/v1/query/#{response_json2[:id]}").
219219
with(headers: headers).
220220
to_return(body: {"session" => "invalid session structure"}.to_json)
221221
statement_client.query_info
222-
end.should raise_error(TrinoHttpError, /Trino API returned unexpected structure at \/v1\/query\/queryid\. Expected Trino::Client::ModelVersions::.*::QueryInfo but got {"session":"invalid session structure"}/)
222+
end.to raise_error(TrinoHttpError, /Trino API returned unexpected structure at \/v1\/query\/queryid\. Expected Trino::Client::ModelVersions::.*::QueryInfo but got {"session":"invalid session structure"}/)
223223
end
224224

225225
it "raises an exception if response format is unexpected" do
226-
lambda do
226+
expect do
227227
stub_request(:get, "http://localhost/v1/query/#{response_json2[:id]}").
228228
with(headers: headers).
229229
to_return(body: "unexpected data structure (not JSON)")
230230
statement_client.query_info
231-
end.should raise_error(TrinoHttpError, /Trino API returned unexpected data format./)
231+
end.to raise_error(TrinoHttpError, /Trino API returned unexpected data format./)
232232
end
233233

234234
it "is redirected if server returned 301" do
@@ -241,7 +241,7 @@
241241
to_return(body: {"queryId" => "queryid"}.to_json)
242242

243243
query_info = statement_client.query_info
244-
query_info.query_id.should == "queryid"
244+
expect(query_info.query_id).to eq "queryid"
245245
end
246246
end
247247

@@ -345,12 +345,12 @@
345345
end
346346

347347
it "forbids using basic auth when ssl is disabled" do
348-
lambda do
348+
expect do
349349
Query.__send__(:faraday_client, {
350350
server: 'localhost',
351351
password: 'abcd'
352352
})
353-
end.should raise_error(ArgumentError)
353+
end.to raise_error(ArgumentError)
354354
end
355355
end
356356

@@ -359,34 +359,34 @@
359359
f = Query.__send__(:faraday_client, {
360360
server: "localhost",
361361
})
362-
f.url_prefix.to_s.should == "http://localhost/"
362+
expect(f.url_prefix.to_s).to eq "http://localhost/"
363363
end
364364

365365
it "is enabled with ssl: true" do
366366
f = Query.__send__(:faraday_client, {
367367
server: "localhost",
368368
ssl: true,
369369
})
370-
f.url_prefix.to_s.should == "https://localhost/"
371-
f.ssl.verify?.should == true
370+
expect(f.url_prefix.to_s).to eq "https://localhost/"
371+
expect(f.ssl.verify?).to eq true
372372
end
373373

374374
it "is enabled with ssl: {verify: false}" do
375375
f = Query.__send__(:faraday_client, {
376376
server: "localhost",
377377
ssl: {verify: false}
378378
})
379-
f.url_prefix.to_s.should == "https://localhost/"
380-
f.ssl.verify?.should == false
379+
expect(f.url_prefix.to_s).to eq "https://localhost/"
380+
expect(f.ssl.verify?).to eq false
381381
end
382382

383383
it "rejects invalid ssl: verify: object" do
384-
lambda do
384+
expect do
385385
f = Query.__send__(:faraday_client, {
386386
server: "localhost",
387387
ssl: {verify: "??"}
388388
})
389-
end.should raise_error(ArgumentError, /String/)
389+
end.to raise_error(ArgumentError, /String/)
390390
end
391391

392392
it "is enabled with ssl: Hash" do
@@ -405,31 +405,31 @@
405405
ssl: ssl,
406406
})
407407

408-
f.url_prefix.to_s.should == "https://localhost/"
409-
f.ssl.verify?.should == true
410-
f.ssl.ca_file.should == ssl[:ca_file]
411-
f.ssl.ca_path.should == ssl[:ca_path]
412-
f.ssl.cert_store.should == ssl[:cert_store]
413-
f.ssl.client_cert.should == ssl[:client_cert]
414-
f.ssl.client_key.should == ssl[:client_key]
408+
expect(f.url_prefix.to_s).to eq "https://localhost/"
409+
expect(f.ssl.verify?).to eq true
410+
expect(f.ssl.ca_file).to eq ssl[:ca_file]
411+
expect(f.ssl.ca_path).to eq ssl[:ca_path]
412+
expect(f.ssl.cert_store).to eq ssl[:cert_store]
413+
expect(f.ssl.client_cert).to eq ssl[:client_cert]
414+
expect(f.ssl.client_key).to eq ssl[:client_key]
415415
end
416416

417417
it "rejects an invalid string" do
418-
lambda do
418+
expect do
419419
Query.__send__(:faraday_client, {
420420
server: "localhost",
421421
ssl: '??',
422422
})
423-
end.should raise_error(ArgumentError, /String/)
423+
end.to raise_error(ArgumentError, /String/)
424424
end
425425

426426
it "rejects an integer" do
427-
lambda do
427+
expect do
428428
Query.__send__(:faraday_client, {
429429
server: "localhost",
430430
ssl: 3,
431431
})
432-
end.should raise_error(ArgumentError, /:ssl/)
432+
end.to raise_error(ArgumentError, /:ssl/)
433433
end
434434
end
435435

@@ -440,13 +440,13 @@
440440

441441
faraday = Faraday.new(url: "http://localhost")
442442
client = StatementClient.new(faraday, query, options.merge(model_version: "316"))
443-
client.current_results.should be_a_kind_of(ModelVersions::V316::QueryResults)
443+
expect(client.current_results).to be_a_kind_of(ModelVersions::V316::QueryResults)
444444
end
445445

446446
it "rejects unsupported model version" do
447-
lambda do
447+
expect do
448448
StatementClient.new(faraday, query, options.merge(model_version: "0.111"))
449-
end.should raise_error(NameError)
449+
end.to raise_error(NameError)
450450
end
451451

452452
let :nested_json do
@@ -543,29 +543,29 @@
543543
stub_request(:get, "localhost/v1/next_uri").
544544
with(headers: headers).
545545
to_return(body: planning_response.to_json)
546-
lambda do
546+
expect do
547547
client.advance
548-
end.should raise_error(Trino::Client::TrinoQueryTimeoutError, "Query queryid timed out")
548+
end.to raise_error(Trino::Client::TrinoQueryTimeoutError, "Query queryid timed out")
549549
end
550550

551551
it "raises TrinoQueryTimeoutError if timeout during initial resuming" do
552552
stub_request(:get, "localhost/v1/next_uri").
553553
with(headers: headers).
554554
to_return(body: lambda { |req| raise Timeout::Error.new("execution expired") })
555555

556-
lambda do
556+
expect do
557557
StatementClient.new(faraday, query, options.merge(timeout_type => 1), "/v1/next_uri")
558-
end.should raise_error(Trino::Client::TrinoQueryTimeoutError, "Query timed out")
558+
end.to raise_error(Trino::Client::TrinoQueryTimeoutError, "Query timed out")
559559
end
560560

561561
it "raises TrinoHttpError if timeout during initial resuming and #{timeout_type} < retry_timeout" do
562562
stub_request(:get, "localhost/v1/next_uri").
563563
with(headers: headers).
564564
to_return(body: lambda { |req| raise Timeout::Error.new("execution expired") })
565565

566-
lambda do
566+
expect do
567567
StatementClient.new(faraday, query, options.merge(timeout_type => 2, retry_timeout: 1), "/v1/next_uri")
568-
end.should raise_error(Trino::Client::TrinoHttpError, "Trino API error due to timeout")
568+
end.to raise_error(Trino::Client::TrinoHttpError, "Trino API error due to timeout")
569569
end
570570
end
571571

@@ -605,9 +605,9 @@
605605
stub_request(:get, "localhost/v1/next_uri").
606606
with(headers: headers).
607607
to_return(body: late_running_response.to_json)
608-
lambda do
608+
expect do
609609
client.advance
610-
end.should raise_error(Trino::Client::TrinoQueryTimeoutError, "Query queryid timed out")
610+
end.to raise_error(Trino::Client::TrinoQueryTimeoutError, "Query queryid timed out")
611611
end
612612

613613
it "doesn't raise errors if query is done" do

0 commit comments

Comments
 (0)