Prevent Aliased Matchers from Overriding Expected Data
Previous Behavior
The aliased matcher implementation of a description currently replaces all instance of the old matcher's name in the new matcher's name. If it happens that the expected values include the old matcher's name, these also get overwritten. In the examples below, the string "include" is replaced in both the outputs by the new matcher's name.
it 'overwrites data for a_string_including' do
my_string = "a string with 'include'"
expect("some random string").to match(a_string_including(my_string))
end
# => expected "some random string" to match
# (a string including "a string with 'a string including'")
it 'overwrites data for a_hash_including' do
my_hash = { my_string: "a string with 'include'" }
expect({}).to match(a_hash_including(my_hash))
end
# => expected {} to match
# (a hash including {:my_string => "a string with 'a hash including'"})
New Behavior
This change makes it so it only replaces the first instance of the original name so none of the expected data is also overwritten. The two above error outputs would be the following:
expected {} to match (a hash including {:my_string => "a string with 'include'"})
expected "some random string" to match (a string including "a string with 'include'")
I saw this in https://github.com/rspec/rspec-rails/issues/1835.
Do you have any questions on how to proceed with this @lnestor ?
@lnestor Are you interested in wrapping this up?
Migrated to the monorepo as rspec/rspec#123