Skip to content

Commit

Permalink
Merge pull request #11691 from koic/fix_an_error_for_gemspec_dependen…
Browse files Browse the repository at this point in the history
…cy_version

Fix an error for `Gemspec/DependencyVersion`
  • Loading branch information
koic committed Mar 12, 2023
2 parents f035637 + a3b8a8d commit e79974b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/fix_an_error_for_gemspec_dependency_version.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#11691](https://github.com/rubocop/rubocop/pull/11691): Fix an error for `Gemspec/DependencyVersion` when method called on gem name argument for `add_dependency`. ([@koic][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/gemspec/dependency_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def on_send(node)
private

def allowed_gem?(node)
allowed_gems.include?(node.first_argument.value)
allowed_gems.include?(node.first_argument.str_content)
end

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

it 'registers an offense when adding dependency without version specification and method called on gem name argument' do
expect_offense(<<~RUBY)
Gem::Specification.new do |spec|
spec.add_dependency('parser'.freeze)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Dependency version specification is required.
end
RUBY
end

it 'registers an offense when adding dependency using git option without version specification' do
expect_offense(<<~RUBY)
Gem::Specification.new do |spec|
Expand Down

0 comments on commit e79974b

Please sign in to comment.