Skip to content

Commit 67bc764

Browse files
committed
Standardize order of expected and actual in tests
Modify integration tests so that the "actual" value is provided before the "expected" value. This makes more sense as we need to say `expected(actual).to <matcher>(expected)`, not the other way around. And if we _are_ saying the other way around, then correct it.
1 parent 27a7970 commit 67bc764

12 files changed

+412
-412
lines changed

spec/integration/rspec/contain_exactly_matcher_spec.rb

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
it "produces the correct failure message when used in the positive" do
77
as_both_colored_and_uncolored do |color_enabled|
88
snippet = <<~TEST.strip
9-
expected = ["Einie", "Marty"]
109
actual = ["Marty", "Jennifer", "Doc"]
10+
expected = ["Einie", "Marty"]
1111
expect(actual).to contain_exactly(*expected)
1212
TEST
1313
program = make_plain_test_program(snippet, color_enabled: color_enabled)
@@ -84,19 +84,19 @@
8484
it "produces the correct failure message when used in the positive" do
8585
as_both_colored_and_uncolored do |color_enabled|
8686
snippet = <<~TEST.strip
87+
actual = [
88+
"Marty McFly",
89+
"Doc Brown",
90+
"Einie",
91+
"Lorraine McFly"
92+
]
8793
expected = [
8894
"Doc Brown",
8995
"Marty McFly",
9096
"Biff Tannen",
9197
"George McFly",
9298
"Lorraine McFly"
9399
]
94-
actual = [
95-
"Marty McFly",
96-
"Doc Brown",
97-
"Einie",
98-
"Lorraine McFly"
99-
]
100100
expect(actual).to contain_exactly(*expected)
101101
TEST
102102
program =
@@ -196,19 +196,19 @@
196196
it "produces the correct failure message when used in the positive" do
197197
as_both_colored_and_uncolored do |color_enabled|
198198
snippet = <<~TEST
199+
actual = [
200+
"Marty McFly",
201+
"Doc Brown",
202+
"Einie",
203+
"Lorraine McFly"
204+
]
199205
expected = [
200206
/ Brown$/,
201207
"Marty McFly",
202208
"Biff Tannen",
203209
/Georg McFly/,
204210
/Lorrain McFly/
205211
]
206-
actual = [
207-
"Marty McFly",
208-
"Doc Brown",
209-
"Einie",
210-
"Lorraine McFly"
211-
]
212212
expect(actual).to contain_exactly(*expected)
213213
TEST
214214
program =
@@ -312,16 +312,16 @@
312312
it "produces the correct failure message" do
313313
as_both_colored_and_uncolored do |color_enabled|
314314
snippet = <<~TEST.strip
315-
expected = [
316-
a_hash_including(foo: "bar"),
317-
a_collection_containing_exactly("zing"),
318-
an_object_having_attributes(baz: "qux"),
319-
]
320315
actual = [
321316
{ foo: "bar" },
322317
double(baz: "qux"),
323318
{ blargh: "riddle" }
324319
]
320+
expected = [
321+
a_hash_including(foo: "bar"),
322+
a_collection_containing_exactly("zing"),
323+
an_object_having_attributes(baz: "qux"),
324+
]
325325
expect(actual).to contain_exactly(*expected)
326326
TEST
327327
program =

spec/integration/rspec/eq_matcher_spec.rb

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,16 @@
173173
it "produces the correct failure message when used in the positive" do
174174
as_both_colored_and_uncolored do |color_enabled|
175175
snippet = <<~RUBY
176-
expected = Time.utc(2011, 12, 13, 14, 15, 16)
177-
actual = Time.utc(2011, 12, 13, 14, 15, 16, 500_000)
178-
expect(expected).to eq(actual)
176+
actual = Time.utc(2011, 12, 13, 14, 15, 16)
177+
expected = Time.utc(2011, 12, 13, 14, 15, 16, 500_000)
178+
expect(actual).to eq(expected)
179179
RUBY
180180
program = make_plain_test_program(snippet, color_enabled: color_enabled)
181181

182182
expected_output =
183183
build_expected_output(
184184
color_enabled: color_enabled,
185-
snippet: "expect(expected).to eq(actual)",
185+
snippet: "expect(actual).to eq(expected)",
186186
expectation:
187187
proc do
188188
line do
@@ -256,16 +256,16 @@
256256
it "produces the correct failure message when used in the positive" do
257257
as_both_colored_and_uncolored do |color_enabled|
258258
snippet = <<~RUBY
259-
expected = Date.new(2023, 10, 14)
260-
actual = Date.new(2023, 10, 31)
261-
expect(expected).to eq(actual)
259+
actual = Date.new(2023, 10, 14)
260+
expected = Date.new(2023, 10, 31)
261+
expect(actual).to eq(expected)
262262
RUBY
263263
program = make_plain_test_program(snippet, color_enabled: color_enabled)
264264

265265
expected_output =
266266
build_expected_output(
267267
color_enabled: color_enabled,
268-
snippet: "expect(expected).to eq(actual)",
268+
snippet: "expect(actual).to eq(expected)",
269269
expectation:
270270
proc do
271271
line do
@@ -328,8 +328,8 @@
328328
it "produces the correct failure message" do
329329
as_both_colored_and_uncolored do |color_enabled|
330330
snippet = <<~TEST.strip
331-
expected = "Something entirely different"
332331
actual = "This is a line\\nAnd that's another line\\n"
332+
expected = "Something entirely different"
333333
expect(actual).to eq(expected)
334334
TEST
335335
program = make_plain_test_program(snippet, color_enabled: color_enabled)
@@ -367,8 +367,8 @@
367367
it "produces the correct failure message" do
368368
as_both_colored_and_uncolored do |color_enabled|
369369
snippet = <<~TEST.strip
370-
expected = "This is a line\\nAnd that's another line\\n"
371370
actual = "Something entirely different"
371+
expected = "This is a line\\nAnd that's another line\\n"
372372
expect(actual).to eq(expected)
373373
TEST
374374
program = make_plain_test_program(snippet, color_enabled: color_enabled)
@@ -406,8 +406,8 @@
406406
it "produces the correct failure message when used in the positive" do
407407
as_both_colored_and_uncolored do |color_enabled|
408408
snippet = <<~TEST.strip
409-
expected = "This is a line\\nAnd that's a line\\nAnd there's a line too\\n"
410409
actual = "This is a line\\nSomething completely different\\nAnd there's a line too\\n"
410+
expected = "This is a line\\nAnd that's a line\\nAnd there's a line too\\n"
411411
expect(actual).to eq(expected)
412412
TEST
413413
program = make_plain_test_program(snippet, color_enabled: color_enabled)
@@ -481,19 +481,6 @@
481481
it "produces the correct failure message when used in the positive" do
482482
as_both_colored_and_uncolored do |color_enabled|
483483
snippet = <<~TEST
484-
expected = [
485-
[
486-
:h1,
487-
[:span, [:text, "Hello world"]],
488-
{
489-
class: "header",
490-
data: {
491-
"sticky" => true,
492-
person: SuperDiff::Test::Person.new(name: "Marty", age: 60)
493-
}
494-
}
495-
]
496-
]
497484
actual = [
498485
[
499486
:h2,
@@ -510,6 +497,19 @@
510497
],
511498
:br
512499
]
500+
expected = [
501+
[
502+
:h1,
503+
[:span, [:text, "Hello world"]],
504+
{
505+
class: "header",
506+
data: {
507+
"sticky" => true,
508+
person: SuperDiff::Test::Person.new(name: "Marty", age: 60)
509+
}
510+
}
511+
]
512+
]
513513
expect(actual).to eq(expected)
514514
TEST
515515
program = make_plain_test_program(snippet, color_enabled: color_enabled)
@@ -620,11 +620,11 @@
620620
it "produces the correct failure message when used in the positive" do
621621
as_both_colored_and_uncolored do |color_enabled|
622622
snippet = <<~TEST.strip
623-
expected = {
623+
actual = {
624624
customer: {
625-
person: SuperDiff::Test::Person.new(name: "Marty McFly", age: 17),
625+
person: SuperDiff::Test::Person.new(name: "Marty McFly, Jr.", age: 17),
626626
shipping_address: {
627-
line_1: "123 Main St.",
627+
line_1: "456 Ponderosa Ct.",
628628
city: "Hill Valley",
629629
state: "CA",
630630
zip: "90382"
@@ -636,14 +636,14 @@
636636
cost: 100_000,
637637
options: ["red", "blue", "green"]
638638
},
639-
{ name: "Chevy 4x4" }
639+
{ name: "Mattel Hoverboard" }
640640
]
641641
}
642-
actual = {
642+
expected = {
643643
customer: {
644-
person: SuperDiff::Test::Person.new(name: "Marty McFly, Jr.", age: 17),
644+
person: SuperDiff::Test::Person.new(name: "Marty McFly", age: 17),
645645
shipping_address: {
646-
line_1: "456 Ponderosa Ct.",
646+
line_1: "123 Main St.",
647647
city: "Hill Valley",
648648
state: "CA",
649649
zip: "90382"
@@ -655,7 +655,7 @@
655655
cost: 100_000,
656656
options: ["red", "blue", "green"]
657657
},
658-
{ name: "Mattel Hoverboard" }
658+
{ name: "Chevy 4x4" }
659659
]
660660
}
661661
expect(actual).to eq(expected)
@@ -776,15 +776,15 @@
776776
it "produces the correct failure message when used in the positive" do
777777
as_both_colored_and_uncolored do |color_enabled|
778778
snippet = <<~TEST.strip
779-
expected = SuperDiff::Test::Person.new(
780-
name: "Marty",
781-
age: 31,
782-
)
783779
actual = SuperDiff::Test::Customer.new(
784780
name: "Doc",
785781
shipping_address: :some_shipping_address,
786782
phone: "1234567890",
787783
)
784+
expected = SuperDiff::Test::Person.new(
785+
name: "Marty",
786+
age: 31,
787+
)
788788
expect(actual).to eq(expected)
789789
TEST
790790
program = make_plain_test_program(snippet, color_enabled: color_enabled)
@@ -855,10 +855,6 @@
855855
it "produces the correct failure message when used in the positive" do
856856
as_both_colored_and_uncolored do |color_enabled|
857857
snippet = <<~TEST.strip
858-
expected = SuperDiff::Test::Item.new(
859-
name: "camera",
860-
quantity: 3,
861-
)
862858
actual = SuperDiff::Test::Player.new(
863859
handle: "mcmire",
864860
character: "Jon",
@@ -867,6 +863,10 @@
867863
health: 4,
868864
ultimate: true,
869865
)
866+
expected = SuperDiff::Test::Item.new(
867+
name: "camera",
868+
quantity: 3,
869+
)
870870
expect(actual).to eq(expected)
871871
TEST
872872
program = make_plain_test_program(snippet, color_enabled: color_enabled)
@@ -937,8 +937,8 @@
937937
it "formats the array correctly in the diff" do
938938
as_both_colored_and_uncolored do |color_enabled|
939939
snippet = <<~TEST.strip
940-
expected = { foo: nil }
941940
actual = { foo: [] }
941+
expected = { foo: nil }
942942
expect(actual).to eq(expected)
943943
TEST
944944
program = make_plain_test_program(snippet, color_enabled: color_enabled)
@@ -978,8 +978,8 @@
978978
it "formats the hash correctly in the diff" do
979979
as_both_colored_and_uncolored do |color_enabled|
980980
snippet = <<~TEST.strip
981-
expected = { foo: nil }
982981
actual = { foo: {} }
982+
expected = { foo: nil }
983983
expect(actual).to eq(expected)
984984
TEST
985985
program = make_plain_test_program(snippet, color_enabled: color_enabled)
@@ -1019,8 +1019,8 @@
10191019
it "formats the object correctly in the diff" do
10201020
as_both_colored_and_uncolored do |color_enabled|
10211021
snippet = <<~TEST.strip
1022-
expected = { foo: nil }
10231022
actual = { foo: SuperDiff::Test::EmptyClass.new }
1023+
expected = { foo: nil }
10241024
expect(actual).to eq(expected)
10251025
TEST
10261026
program = make_plain_test_program(snippet, color_enabled: color_enabled)

0 commit comments

Comments
 (0)