Skip to content

Commit bf6e657

Browse files
Modernize RSpec tests to use expect syntax exclusively (#146)
1 parent f9653b3 commit bf6e657

4 files changed

Lines changed: 95 additions & 95 deletions

File tree

spec/api_client_spec.rb

Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def json(data)
7676
.with(headers: request_headers, body: req.message)
7777
.to_return(status: 200, body: { delivery_id: 1 }.to_json, headers: {})
7878

79-
client.send_email(req).should eq({ "delivery_id" => 1 })
79+
expect(client.send_email(req)).to eq({ "delivery_id" => 1 })
8080
end
8181

8282
it "handles validation failures (400)" do
@@ -93,10 +93,10 @@ def json(data)
9393
.with(headers: request_headers, body: req.message)
9494
.to_return(status: 400, body: err_json, headers: {})
9595

96-
lambda { client.send_email(req) }.should(
96+
expect { client.send_email(req) }.to(
9797
raise_error(Customerio::InvalidResponse) { |error|
98-
error.message.should eq "example error"
99-
error.code.should eq "400"
98+
expect(error.message).to eq("example error")
99+
expect(error.code).to eq("400")
100100
}
101101
)
102102
end
@@ -113,10 +113,10 @@ def json(data)
113113
.with(headers: request_headers, body: req.message)
114114
.to_return(status: 500, body: "Server unavailable", headers: {})
115115

116-
lambda { client.send_email(req) }.should(
116+
expect { client.send_email(req) }.to(
117117
raise_error(Customerio::InvalidResponse) { |error|
118-
error.message.should eq "Server unavailable"
119-
error.code.should eq "500"
118+
expect(error.message).to eq("Server unavailable")
119+
expect(error.code).to eq("500")
120120
}
121121
)
122122
end
@@ -130,7 +130,7 @@ def json(data)
130130
)
131131

132132
req.attach('test', content, encode: false)
133-
req.message[:attachments]['test'].should eq content
133+
expect(req.message[:attachments]['test']).to eq(content)
134134

135135
stub_request(:post, api_uri('/v1/send/email'))
136136
.with(headers: request_headers, body: req.message)
@@ -148,7 +148,7 @@ def json(data)
148148
)
149149

150150
req.attach('test', content)
151-
req.message[:attachments]['test'].should eq Base64.strict_encode64(content)
151+
expect(req.message[:attachments]['test']).to eq(Base64.strict_encode64(content))
152152

153153
stub_request(:post, api_uri('/v1/send/email'))
154154
.with(headers: request_headers, body: req.message)
@@ -165,8 +165,8 @@ def json(data)
165165

166166
req.attach('test', 'test-content')
167167

168-
lambda { req.attach('test', '') }.should raise_error(/attachment test already exists/)
169-
req.message[:attachments].should eq({ "test" => Base64.strict_encode64("test-content") })
168+
expect { req.attach('test', '') }.to raise_error(/attachment test already exists/)
169+
expect(req.message[:attachments]).to eq({ "test" => Base64.strict_encode64("test-content") })
170170
end
171171
end
172172

@@ -183,7 +183,7 @@ def json(data)
183183
.with(headers: request_headers, body: req.message)
184184
.to_return(status: 200, body: { delivery_id: 1 }.to_json, headers: {})
185185

186-
client.send_push(req).should eq({ "delivery_id" => 1 })
186+
expect(client.send_push(req)).to eq({ "delivery_id" => 1 })
187187
end
188188

189189
it "handles validation failures (400)" do
@@ -200,10 +200,10 @@ def json(data)
200200
.with(headers: request_headers, body: req.message)
201201
.to_return(status: 400, body: err_json, headers: {})
202202

203-
lambda { client.send_push(req) }.should(
203+
expect { client.send_push(req) }.to(
204204
raise_error(Customerio::InvalidResponse) { |error|
205-
error.message.should eq "example error"
206-
error.code.should eq "400"
205+
expect(error.message).to eq("example error")
206+
expect(error.code).to eq("400")
207207
}
208208
)
209209
end
@@ -220,10 +220,10 @@ def json(data)
220220
.with(headers: request_headers, body: req.message)
221221
.to_return(status: 500, body: "Server unavailable", headers: {})
222222

223-
lambda { client.send_push(req) }.should(
223+
expect { client.send_push(req) }.to(
224224
raise_error(Customerio::InvalidResponse) { |error|
225-
error.message.should eq "Server unavailable"
226-
error.code.should eq "500"
225+
expect(error.message).to eq("Server unavailable")
226+
expect(error.code).to eq("500")
227227
}
228228
)
229229
end
@@ -240,7 +240,7 @@ def json(data)
240240
}
241241
)
242242

243-
req.message[:custom_device].should eq({
243+
expect(req.message[:custom_device]).to eq({
244244
platform: 'ios',
245245
token: 'sample-token',
246246
})
@@ -249,7 +249,7 @@ def json(data)
249249
.with(headers: request_headers, body: req.message)
250250
.to_return(status: 200, body: { delivery_id: 2 }.to_json, headers: {})
251251

252-
client.send_push(req).should eq({ "delivery_id" => 2 })
252+
expect(client.send_push(req)).to eq({ "delivery_id" => 2 })
253253
end
254254
end
255255

@@ -266,7 +266,7 @@ def json(data)
266266
.with(headers: request_headers, body: req.message)
267267
.to_return(status: 200, body: { delivery_id: 1 }.to_json, headers: {})
268268

269-
client.send_sms(req).should eq({ "delivery_id" => 1 })
269+
expect(client.send_sms(req)).to eq({ "delivery_id" => 1 })
270270
end
271271

272272
it "handles validation failures (400)" do
@@ -283,10 +283,10 @@ def json(data)
283283
.with(headers: request_headers, body: req.message)
284284
.to_return(status: 400, body: err_json, headers: {})
285285

286-
lambda { client.send_sms(req) }.should(
286+
expect { client.send_sms(req) }.to(
287287
raise_error(Customerio::InvalidResponse) { |error|
288-
error.message.should eq "example error"
289-
error.code.should eq "400"
288+
expect(error.message).to eq("example error")
289+
expect(error.code).to eq("400")
290290
}
291291
)
292292
end
@@ -303,10 +303,10 @@ def json(data)
303303
.with(headers: request_headers, body: req.message)
304304
.to_return(status: 500, body: "Server unavailable", headers: {})
305305

306-
lambda { client.send_sms(req) }.should(
306+
expect { client.send_sms(req) }.to(
307307
raise_error(Customerio::InvalidResponse) { |error|
308-
error.message.should eq "Server unavailable"
309-
error.code.should eq "500"
308+
expect(error.message).to eq("Server unavailable")
309+
expect(error.code).to eq("500")
310310
}
311311
)
312312
end
@@ -325,7 +325,7 @@ def json(data)
325325
.with(headers: request_headers, body: req.message)
326326
.to_return(status: 200, body: { delivery_id: 1 }.to_json, headers: {})
327327

328-
client.send_inbox_message(req).should eq({ "delivery_id" => 1 })
328+
expect(client.send_inbox_message(req)).to eq({ "delivery_id" => 1 })
329329
end
330330

331331
it "handles validation failures (400)" do
@@ -342,10 +342,10 @@ def json(data)
342342
.with(headers: request_headers, body: req.message)
343343
.to_return(status: 400, body: err_json, headers: {})
344344

345-
lambda { client.send_inbox_message(req) }.should(
345+
expect { client.send_inbox_message(req) }.to(
346346
raise_error(Customerio::InvalidResponse) { |error|
347-
error.message.should eq "example error"
348-
error.code.should eq "400"
347+
expect(error.message).to eq("example error")
348+
expect(error.code).to eq("400")
349349
}
350350
)
351351
end
@@ -362,10 +362,10 @@ def json(data)
362362
.with(headers: request_headers, body: req.message)
363363
.to_return(status: 500, body: "Server unavailable", headers: {})
364364

365-
lambda { client.send_inbox_message(req) }.should(
365+
expect { client.send_inbox_message(req) }.to(
366366
raise_error(Customerio::InvalidResponse) { |error|
367-
error.message.should eq "Server unavailable"
368-
error.code.should eq "500"
367+
expect(error.message).to eq("Server unavailable")
368+
expect(error.code).to eq("500")
369369
}
370370
)
371371
end
@@ -384,7 +384,7 @@ def json(data)
384384
.with(headers: request_headers, body: req.message)
385385
.to_return(status: 200, body: { delivery_id: 1 }.to_json, headers: {})
386386

387-
client.send_in_app(req).should eq({ "delivery_id" => 1 })
387+
expect(client.send_in_app(req)).to eq({ "delivery_id" => 1 })
388388
end
389389

390390
it "handles validation failures (400)" do
@@ -401,10 +401,10 @@ def json(data)
401401
.with(headers: request_headers, body: req.message)
402402
.to_return(status: 400, body: err_json, headers: {})
403403

404-
lambda { client.send_in_app(req) }.should(
404+
expect { client.send_in_app(req) }.to(
405405
raise_error(Customerio::InvalidResponse) { |error|
406-
error.message.should eq "example error"
407-
error.code.should eq "400"
406+
expect(error.message).to eq("example error")
407+
expect(error.code).to eq("400")
408408
}
409409
)
410410
end
@@ -421,10 +421,10 @@ def json(data)
421421
.with(headers: request_headers, body: req.message)
422422
.to_return(status: 500, body: "Server unavailable", headers: {})
423423

424-
lambda { client.send_in_app(req) }.should(
424+
expect { client.send_in_app(req) }.to(
425425
raise_error(Customerio::InvalidResponse) { |error|
426-
error.message.should eq "Server unavailable"
427-
error.code.should eq "500"
426+
expect(error.message).to eq("Server unavailable")
427+
expect(error.code).to eq("500")
428428
}
429429
)
430430
end
@@ -442,7 +442,7 @@ def json(data)
442442
.with(headers: request_headers, body: req.message)
443443
.to_return(status: 200, body: { trigger_id: "abc123" }.to_json, headers: {})
444444

445-
client.trigger_broadcast(req).should eq({ "trigger_id" => "abc123" })
445+
expect(client.trigger_broadcast(req)).to eq({ "trigger_id" => "abc123" })
446446
end
447447

448448
it "sends with email list audience" do
@@ -457,7 +457,7 @@ def json(data)
457457
.with(headers: request_headers, body: req.message)
458458
.to_return(status: 200, body: { trigger_id: "abc123" }.to_json, headers: {})
459459

460-
client.trigger_broadcast(req).should eq({ "trigger_id" => "abc123" })
460+
expect(client.trigger_broadcast(req)).to eq({ "trigger_id" => "abc123" })
461461
end
462462

463463
it "sends with id list audience" do
@@ -471,7 +471,7 @@ def json(data)
471471
.with(headers: request_headers, body: req.message)
472472
.to_return(status: 200, body: { trigger_id: "abc123" }.to_json, headers: {})
473473

474-
client.trigger_broadcast(req).should eq({ "trigger_id" => "abc123" })
474+
expect(client.trigger_broadcast(req)).to eq({ "trigger_id" => "abc123" })
475475
end
476476

477477
it "sends with data_file_url audience" do
@@ -484,35 +484,35 @@ def json(data)
484484
.with(headers: request_headers, body: req.message)
485485
.to_return(status: 200, body: { trigger_id: "abc123" }.to_json, headers: {})
486486

487-
client.trigger_broadcast(req).should eq({ "trigger_id" => "abc123" })
487+
expect(client.trigger_broadcast(req)).to eq({ "trigger_id" => "abc123" })
488488
end
489489

490490
it "raises an error when broadcast_id is missing" do
491-
lambda {
491+
expect {
492492
Customerio::TriggerBroadcastRequest.new(data: { headline: "Test" })
493-
}.should raise_error(ArgumentError, "broadcast_id is required")
493+
}.to raise_error(ArgumentError, "broadcast_id is required")
494494
end
495495

496496
it "raises an error when broadcast_id is not an integer" do
497-
lambda {
497+
expect {
498498
Customerio::TriggerBroadcastRequest.new(broadcast_id: "12")
499-
}.should raise_error(ArgumentError, "broadcast_id must be an integer")
499+
}.to raise_error(ArgumentError, "broadcast_id must be an integer")
500500
end
501501

502502
it "raises an error when multiple audience fields are provided" do
503-
lambda {
503+
expect {
504504
Customerio::TriggerBroadcastRequest.new(
505505
broadcast_id: 12,
506506
emails: ["a@example.com"],
507507
ids: [1, 2],
508508
)
509-
}.should raise_error(ArgumentError, /only one of/)
509+
}.to raise_error(ArgumentError, /only one of/)
510510
end
511511

512512
it "raises an error when request is not a TriggerBroadcastRequest" do
513-
lambda {
513+
expect {
514514
client.trigger_broadcast("not a request")
515-
}.should raise_error(ArgumentError, /must be an instance of/)
515+
}.to raise_error(ArgumentError, /must be an instance of/)
516516
end
517517

518518
it "handles validation failures (400)" do
@@ -527,10 +527,10 @@ def json(data)
527527
.with(headers: request_headers, body: req.message)
528528
.to_return(status: 400, body: err_json, headers: {})
529529

530-
lambda { client.trigger_broadcast(req) }.should(
530+
expect { client.trigger_broadcast(req) }.to(
531531
raise_error(Customerio::InvalidResponse) { |error|
532-
error.message.should eq "example error"
533-
error.code.should eq "400"
532+
expect(error.message).to eq("example error")
533+
expect(error.code).to eq("400")
534534
}
535535
)
536536
end
@@ -544,10 +544,10 @@ def json(data)
544544
.with(headers: request_headers, body: req.message)
545545
.to_return(status: 500, body: "Server unavailable", headers: {})
546546

547-
lambda { client.trigger_broadcast(req) }.should(
547+
expect { client.trigger_broadcast(req) }.to(
548548
raise_error(Customerio::InvalidResponse) { |error|
549-
error.message.should eq "Server unavailable"
550-
error.code.should eq "500"
549+
expect(error.message).to eq("Server unavailable")
550+
expect(error.code).to eq("500")
551551
}
552552
)
553553
end

spec/base_client_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def api_client_request_headers
7373
with(headers: api_client_request_headers).
7474
to_return(status: 400, body: "", headers: {})
7575

76-
lambda { api_client.request_and_verify_response(:put, '/some/path', "") }.should(
76+
expect { api_client.request_and_verify_response(:put, '/some/path', "") }.to(
7777
raise_error(Customerio::InvalidResponse)
7878
)
7979
end
@@ -83,7 +83,7 @@ def api_client_request_headers
8383
with(headers: api_client_request_headers).
8484
to_return(status: 200, body: "Test", headers: {})
8585

86-
api_client.request_and_verify_response(:put, '/some/path', "").body.should eq("Test")
86+
expect(api_client.request_and_verify_response(:put, '/some/path', "").body).to eq("Test")
8787
end
8888
end
8989
end

0 commit comments

Comments
 (0)