Skip to content

Commit

Permalink
Fix bug with range in RepeatedIncludeExample cop
Browse files Browse the repository at this point in the history
  • Loading branch information
hasghari committed Apr 7, 2024
1 parent 536c9c3 commit f4ec75f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Master (Unreleased)

- Fix beginless and endless range bug for RepeatedIncludeExample cop. ([@hasghari])

## 2.29.1 (2024-04-05)

- Fix an error in the default configuration. ([@ydah])
Expand Down Expand Up @@ -895,6 +897,7 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
[@gsamokovarov]: https://github.com/gsamokovarov
[@harry-graham]: https://github.com/harry-graham
[@harrylewis]: https://github.com/harrylewis
[@hasghari]: https://github.com/hasghari
[@hosamaly]: https://github.com/hosamaly
[@ignaciovillaverde]: https://github.com/ignaciovillaverde
[@jaredbeck]: https://github.com/jaredbeck
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/rspec/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Node
def recursive_literal_or_const?
case type
when :begin, :pair, *AST::Node::COMPOSITE_LITERALS
children.all?(&:recursive_literal_or_const?)
children.compact.all?(&:recursive_literal_or_const?)
else
literal? || const_type?
end
Expand Down
18 changes: 18 additions & 0 deletions spec/rubocop/cop/rspec/repeated_include_example_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,5 +233,23 @@
end
RUBY
end

it 'allows for beginless ranges' do
expect_no_offenses(<<~RUBY)
describe 'foo' do
include_examples 'irange', ..1
it_behaves_like 'irange', ..2
end
RUBY
end

it 'allows for endless ranges' do
expect_no_offenses(<<~RUBY)
describe 'foo' do
include_examples 'erange', (1..)
it_behaves_like 'erange', (2..)
end
RUBY
end
end
end

0 comments on commit f4ec75f

Please sign in to comment.