From f4ec75f7fdc665e19046426cdbc1030bc35900f2 Mon Sep 17 00:00:00 2001 From: Hamed Asghari Date: Sat, 6 Apr 2024 08:48:35 -0400 Subject: [PATCH] Fix bug with range in RepeatedIncludeExample cop --- CHANGELOG.md | 3 +++ lib/rubocop/rspec/node.rb | 2 +- .../cop/rspec/repeated_include_example_spec.rb | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f0803f86..b9a12b28b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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]) @@ -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 diff --git a/lib/rubocop/rspec/node.rb b/lib/rubocop/rspec/node.rb index 2721e9fe2..0dc6a2d42 100644 --- a/lib/rubocop/rspec/node.rb +++ b/lib/rubocop/rspec/node.rb @@ -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 diff --git a/spec/rubocop/cop/rspec/repeated_include_example_spec.rb b/spec/rubocop/cop/rspec/repeated_include_example_spec.rb index d47e4ba07..53d20b64d 100644 --- a/spec/rubocop/cop/rspec/repeated_include_example_spec.rb +++ b/spec/rubocop/cop/rspec/repeated_include_example_spec.rb @@ -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