Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module SuperDiff
module RSpec
module OperationTreeBuilders
class HashIncluding < SuperDiff::OperationTreeBuilders::Hash
include ::RSpec::Matchers::Composable

def self.applies_to?(expected, actual)
(
SuperDiff::RSpec.a_hash_including_something?(expected) ||
Expand All @@ -23,7 +25,7 @@ def initialize(expected:, **rest)
def should_add_noop_operation?(key)
!expected.include?(key) || (
actual.include?(key) &&
expected[key] == actual[key]
values_match?(expected[key], actual[key])
)
end
end
Expand Down
95 changes: 95 additions & 0 deletions spec/integration/rspec/include_matcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,46 @@
in_color(color_enabled)
end
end

it "produces the correct failure message when fuzzy matching" do
as_both_colored_and_uncolored do |color_enabled|
snippet = <<~TEST.strip
expected = { number: a_kind_of(Numeric), city: /burb/i, state: "CA" }
actual = { number: 42, city: "Burbank", zip: "90210" }
expect(actual).to include(expected)
TEST
program = make_plain_test_program(
snippet,
color_enabled: color_enabled,
)

expected_output = build_expected_output(
color_enabled: color_enabled,
snippet: %|expect(actual).to include(expected)|,
expectation: proc {
line do
plain %|Expected |
actual %|{ number: 42, city: "Burbank", zip: "90210" }|
plain %| to include |
expected %|(state: "CA")|
plain %|.|
end
},
diff: proc {
plain_line %| {|
plain_line %| number: 42,|
plain_line %| city: "Burbank",|
plain_line %| zip: "90210"|
expected_line %|- state: "CA"|
plain_line %| }|
},
)

expect(program).
to produce_output_when_run(expected_output).
in_color(color_enabled)
end
end
end

context "that is large" do
Expand Down Expand Up @@ -345,6 +385,61 @@
in_color(color_enabled)
end
end

it "produces the correct failure message when fuzzy matching" do
as_both_colored_and_uncolored do |color_enabled|
snippet = <<~TEST.strip
expected = {
number: a_kind_of(Numeric),
street: "Yoshie Circles",
city: /burb/i,
zip: "90382"
}
actual = {
number: 42,
street: "Yoshie Circles",
city: "Burbank",
state: "CA",
zip: "90210"
}
expect(actual).to include(expected)
TEST
program = make_plain_test_program(
snippet,
color_enabled: color_enabled,
)

expected_output = build_expected_output(
color_enabled: color_enabled,
snippet: %|expect(actual).to include(expected)|,
expectation: proc {
line do
plain %| Expected |
actual %|{ number: 42, street: "Yoshie Circles", city: "Burbank", state: "CA", zip: "90210" }|
end

line do
plain %|to include |
expected %|(zip: "90382")|
end
},
diff: proc {
plain_line %| {|
plain_line %| number: 42,|
plain_line %| street: "Yoshie Circles",|
plain_line %| city: "Burbank",|
plain_line %| state: "CA",|
expected_line %|- zip: "90382"|
actual_line %|+ zip: "90210"|
plain_line %| }|
},
)

expect(program).
to produce_output_when_run(expected_output).
in_color(color_enabled)
end
end
end
end
end