Skip to content

Commit

Permalink
Merge pull request #1437 from rubocop/fix-mistaken-positional-argumen…
Browse files Browse the repository at this point in the history
…ts-reordering

Skip reordering positional arguments for include_* in RSpec/SortMetadata
  • Loading branch information
bquorning committed Oct 25, 2022
1 parent e124e7e commit 58da998
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Master (Unreleased)

- Fix autocorrection loop in `RSpec/ExampleWording` for insufficient example wording. ([@pirj])
- Fix `RSpec/SortMetadata` not to reorder arguments of `include_`/`it_behaves_like`. ([@pirj])
- Fix a false positive for `RSpec/NoExpectationExample` when allowed pattern methods with arguments. ([@ydah])

## 2.14.1 (2022-10-24)
Expand Down
3 changes: 1 addition & 2 deletions lib/rubocop/cop/rspec/sort_metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ class SortMetadata < Base
def_node_matcher :rspec_metadata, <<~PATTERN
(block
(send
#rspec? {#Examples.all #ExampleGroups.all #SharedGroups.all #Hooks.all #Includes.all}
_ ${send str sym}* (hash $...)?)
#rspec? {#Examples.all #ExampleGroups.all #SharedGroups.all #Hooks.all} _ ${send str sym}* (hash $...)?)
...)
PATTERN

Expand Down
33 changes: 13 additions & 20 deletions spec/rubocop/cop/rspec/sort_metadata_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,17 @@
RUBY
end

it "ignores includes' positional arguments" do
expect_no_offenses(<<~RUBY)
include_examples 'z', 'a' do
end
it_behaves_like 'z', 'a' do
end
include_context 'z', 'a' do
end
RUBY
end

context 'when using custom RSpec language ' \
'without adjusting the RuboCop RSpec language configuration' do
it 'does not register an offense' do
Expand All @@ -179,31 +190,13 @@
'and adjusting the RuboCop RSpec language configuration' do
before do
other_cops.tap do |config|
config.dig('RSpec', 'Language', 'Includes', 'Context').push(
config.dig('RSpec', 'Language', 'ExampleGroups', 'Regular').push(
'describan', 'contexto_compartido'
)
config.dig('RSpec', 'Language', 'Includes', 'Examples').push('ejemplo')
config.dig('RSpec', 'Language', 'Examples', 'Regular').push('ejemplo')
end
end

let(:language_config) do
<<~YAML
RSpec:
Language:
ExampleGroups:
Regular:
- describan
Examples:
Regular:
- ejemplo
Hooks:
- antes
SharedGroups:
Context:
- contexto_compartido
YAML
end

it 'registers an offense' do
expect_offense(<<~RUBY)
RSpec.describan "Algo", :b, :a do
Expand Down

0 comments on commit 58da998

Please sign in to comment.