Skip to content

Commit

Permalink
Merge pull request #1438 from rubocop/fix-infinite-correction-loop
Browse files Browse the repository at this point in the history
Fix infinite correction loop in RSpec/ExampleWording
  • Loading branch information
pirj authored and bquorning committed Oct 25, 2022
1 parent cbf5814 commit e124e7e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Master (Unreleased)

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

## 2.14.1 (2022-10-24)
Expand Down
15 changes: 7 additions & 8 deletions lib/rubocop/cop/rspec/example_wording.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,15 @@ def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
add_wording_offense(description_node, MSG_SHOULD)
elsif message.match?(IT_PREFIX)
add_wording_offense(description_node, MSG_IT)
else
check_and_handle_insufficient_examples(description_node)
elsif insufficient_docstring?(description_node)
add_offense(docstring(description_node),
message: MSG_INSUFFICIENT_DESCRIPTION)
end
end
end

private

def check_and_handle_insufficient_examples(description)
if insufficient_examples.include?(preprocess(text(description)))
add_wording_offense(description, MSG_INSUFFICIENT_DESCRIPTION)
end
end

def add_wording_offense(node, message)
docstring = docstring(node)

Expand Down Expand Up @@ -137,6 +132,10 @@ def ignored_words
cop_config.fetch('IgnoredWords', [])
end

def insufficient_docstring?(description_node)
insufficient_examples.include?(preprocess(text(description_node)))
end

def insufficient_examples
examples = cop_config.fetch('DisallowedExamples', [])
examples.map! { |example| preprocess(example) }
Expand Down

0 comments on commit e124e7e

Please sign in to comment.