Skip to content

Commit c356609

Browse files
committed
Ensure that negative versions of matchers are tested
1 parent a2ee9b4 commit c356609

15 files changed

+2457
-346
lines changed

lib/super_diff/rspec/differ.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def worth_diffing?
4444
end
4545

4646
def comparing_inequal_values?
47-
expected != actual
47+
!helpers.values_match?(expected, actual)
4848
end
4949

5050
def comparing_primitive_values?
@@ -59,6 +59,16 @@ def comparing_singleline_strings?
5959
!expected.include?("\n") &&
6060
!actual.include?("\n")
6161
end
62+
63+
def helpers
64+
@_helpers ||= Helpers.new
65+
end
66+
67+
class Helpers
68+
include ::RSpec::Matchers::Composable
69+
70+
public :values_match?
71+
end
6272
end
6373
end
6474
end

lib/super_diff/rspec/matcher_text_builders/be_predicate.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def initialize(
1818

1919
def expected_action_for_failure_message
2020
if predicate_accessible?
21-
"return true for"
21+
"return a truthy result for"
2222
elsif private_predicate?
2323
"have a public method"
2424
else

lib/super_diff/rspec/monkey_patches.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,8 @@ def expected_for_description
380380

381381
# Override to use readable_list_of
382382
def expected_for_failure_message
383+
# TODO: Switch to using @divergent_items and handle this in the text
384+
# builder
383385
readable_list_of(@divergent_items).lstrip
384386
end
385387

spec/integration/rspec/be_falsey_matcher_spec.rb

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require "spec_helper"
22

33
RSpec.describe "Integration with RSpec's #be_falsey matcher", type: :integration do
4-
it "produces the correct failure message" do
4+
it "produces the correct failure message when used in the positive" do
55
as_both_colored_and_uncolored do |color_enabled|
66
snippet = %|expect(:foo).to be_falsey|
77
program = make_plain_test_program(snippet, color_enabled: color_enabled)
@@ -25,4 +25,29 @@
2525
in_color(color_enabled)
2626
end
2727
end
28+
29+
it "produces the correct failure message when used in the negative" do
30+
as_both_colored_and_uncolored do |color_enabled|
31+
snippet = %|expect(false).not_to be_falsey|
32+
program = make_plain_test_program(snippet, color_enabled: color_enabled)
33+
34+
expected_output = build_expected_output(
35+
color_enabled: color_enabled,
36+
snippet: snippet,
37+
expectation: proc {
38+
line do
39+
plain "Expected "
40+
green %|false|
41+
plain " not to be "
42+
red %|falsey|
43+
plain "."
44+
end
45+
},
46+
)
47+
48+
expect(program).
49+
to produce_output_when_run(expected_output).
50+
in_color(color_enabled)
51+
end
52+
end
2853
end

0 commit comments

Comments
 (0)