-
-
Notifications
You must be signed in to change notification settings - Fork 290
RSpec/SpecFilePathFormat allow multiple values for same key in IgnoreMetadata #2070
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
Changes from 1 commit
cd98181
055b97b
0816629
0f0fb8b
bfe68bc
14f3dd2
8c4429e
c25abf4
7bf9936
ce6d89a
62d2662
d59185b
cd2f7b0
71de1e8
8bcbbf3
473104b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -32,6 +32,11 @@ module RSpec | |||||||
| # # good | ||||||||
| # whatever_spec.rb # describe MyClass, type: :routing do; end | ||||||||
| # | ||||||||
| # @example `IgnoreMetadata: {type=>[routing,models]}` (default) | ||||||||
|
Member
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. Is it really configured like this in YAML? |
||||||||
| # # good | ||||||||
| # whatever_spec.rb # describe MyClass, type: :routing do; end | ||||||||
| # whatever_spec.rb # describe MyClass, type: :models do; end | ||||||||
|
Member
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. What if the metadata's value IS an array? RSpec.describe Airplane, prepare: [:fuel] doHow do we define IgnoreMetadata in YAML?
Member
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. Side note: how do we ignore any value for a key?
Member
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. I'm hinting towards: IgnoreMetadata:
- prepare
- type: model
- type: routing
- skip: [database]Luckily enough, YAML allows to mix all that, and to cover all ignored cases unambiguously. |
||||||||
| # | ||||||||
| class SpecFilePathFormat < Base | ||||||||
| include TopLevelGroup | ||||||||
| include Namespace | ||||||||
|
|
@@ -73,7 +78,10 @@ def ensure_correct_file_path(send_node, class_name, arguments) | |||||||
| def ignore_metadata?(arguments) | ||||||||
| arguments.any? do |argument| | ||||||||
| metadata_key_value(argument).any? do |key, value| | ||||||||
| ignore_metadata.values_at(key.to_s).include?(value.to_s) | ||||||||
| ignore_values = ignore_metadata[key.to_s] | ||||||||
| ignore_values = [ignore_values] unless ignore_values.is_a?(Array) | ||||||||
|
Collaborator
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. You can use
Suggested change
|
||||||||
|
|
||||||||
| ignore_values.include?(value.to_s) | ||||||||
| end | ||||||||
| end | ||||||||
| end | ||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -281,4 +281,14 @@ class Foo | |
| RUBY | ||
| end | ||
| end | ||
|
|
||
| context 'when configured with `IgnoreMetadata: { "foo" => ["bar"] }`' do | ||
|
Collaborator
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. I think maybe you should write a spec for
Author
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. Fair, are the amended specs what you had in mind? I needed to play around with the wording a bit, since I was over the line length limit by one and two characters respectively, by using the existing phrasing.
Member
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. Sorry for ignorance, but what if the value of the metdata value is an array of bar baz? I haven’t glanced over the changes, but if we happen to want to allow multiple values, there will be less ambiguity if we accept accept a list of metadata to ignore. Will it work? |
||
| let(:cop_config) { { 'IgnoreMetadata' => { 'foo' => ['bar'] } } } | ||
|
|
||
| it 'does not register an offense when include ignored metadata' do | ||
| expect_no_offenses(<<~RUBY, 'wrong_class_spec.rb') | ||
| describe MyClass, foo: :bar do; end | ||
| RUBY | ||
| end | ||
| end | ||
| end | ||
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.
This change is unnecessary. Could you please revert?
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.
Sure, however I'd like to confirm that the revert would be correct, as the Pull Request template specifically states:
and this PR does change an existing cops configuration options.
Uh oh!
There was an error while loading. Please reload this page.
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.
According to my understanding, "modified an existing cop's configuration options" refers to instances such as when adding a new configuration option, changing a name, or for example, when adding autocorrect functionality and adding
Autocorrect: true, we should addVersionChanged: "<<next>>".