Skip to content
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

[Fix #12714] Fix an error for Gemspec/RequiredRubyVersion #12715

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#12714](https://github.com/rubocop/rubocop/issues/12714): Fix an error for `Gemspec/RequiredRubyVersion` when `required_ruby_version` is specified with `Gem::Requirement.new` and is higher than `TargetRubyVersion`. ([@koic][])
2 changes: 2 additions & 0 deletions lib/rubocop/cop/gemspec/required_ruby_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ def extract_ruby_version(required_ruby_version)
end
end

return unless required_ruby_version

required_ruby_version.str_content.scan(/\d/).first(2).join('.')
end

Expand Down
9 changes: 9 additions & 0 deletions spec/rubocop/cop/gemspec/required_ruby_version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@
RUBY
end

it 'registers an offense when `required_ruby_version` is specified with `Gem::Requirement.new` and is higher than `TargetRubyVersion`' do
expect_offense(<<~RUBY)
Gem::Specification.new do |spec|
spec.required_ruby_version = Gem::Requirement.new('< 3.4')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `required_ruby_version` and `TargetRubyVersion` (2.7, which may be specified in .rubocop.yml) should be equal.
end
RUBY
end

it 'recognizes a Gem::Requirement with multiple requirements and does not register an offense' do
expect_no_offenses(<<~RUBY)
Gem::Specification.new do |spec|
Expand Down