-
-
Notifications
You must be signed in to change notification settings - Fork 395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent Aliased Matchers from Overriding Expected Data #1116
Open
lnestor
wants to merge
5
commits into
rspec:main
Choose a base branch
from
lnestor:repeating-aliased-matcher-descriptions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4bc09e8
Prevent aliased matchers from overriding data
bee5647
Give option to override aliased matcher name no matter the position
7e54f1f
Remove lambda default parameter to maintain ruby compatability
16b836b
Split aliased matcher description into new class
514ba9e
Remove keyword arguments for backwards compatibility
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,6 +79,19 @@ def description | |
expect(matcher.description).to eq("my blockless override description") | ||
end | ||
|
||
RSpec::Matchers.define :my_repeating_base_matcher do | ||
def description | ||
"my repeating base matcher my repeating base matcher" | ||
end | ||
end | ||
|
||
RSpec::Matchers.alias_matcher :my_repeating_override, :my_repeating_base_matcher | ||
|
||
it 'does not override data in the description with the same name as the matcher' do | ||
matcher = my_repeating_override | ||
expect(matcher.description).to eq("my repeating override my repeating base matcher") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It'd prefer a practical example showing the problem using |
||
end | ||
|
||
it 'works properly with a chained method off a negated matcher' do | ||
expect { }.to avoid_outputting.to_stdout | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this needs to only match the start of the string, this might still accidentally override terms if the original description is not generated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback! Can you clarify this a bit?
#sub
matches the first occurrence, so are you saying something like matching the first n characters of the string?Also, what do you mean by if the original description is not generated? Since
BaseMatcher
implements description, I would think that they all would have a description. Unless a class implements its own description which does not contain the name of the matcher.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"hello_old_name".sub("old_name","new_name")
would produce"hello_new_name"
but we don't want that. We only want to replaceold_name
as it was generated initially.Similarly it is possible for matchers to implement
description
themselves and it might mean they don't contain the old_name at all, in this case we shouldn't be replacing the first instance blindly as it might not be in the description but in the expected.