/
duplicated_gem_spec.rb
67 lines (60 loc) · 1.85 KB
/
duplicated_gem_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# frozen_string_literal: true
RSpec.describe RuboCop::Cop::Bundler::DuplicatedGem, :config do
let(:cop_config) { { 'Include' => ['**/Gemfile'] } }
context 'when investigating Ruby files' do
it 'does not register any offenses' do
expect_no_offenses(<<~RUBY, 'foo.rb')
# cop will not read these contents
gem('rubocop')
gem('rubocop')
RUBY
end
end
context 'when investigating Gemfiles' do
context 'and the file is empty' do
it 'does not register any offenses' do
expect_no_offenses('', 'Gemfile')
end
end
context 'and no duplicate gems are present' do
it 'does not register any offenses' do
expect_no_offenses(<<~RUBY, 'Gemfile')
gem 'rubocop'
gem 'flog'
RUBY
end
end
context 'and a gem is duplicated in default group' do
it 'registers an offense' do
expect_offense(<<-GEM, 'Gemfile')
source 'https://rubygems.org'
gem 'rubocop'
gem 'rubocop'
^^^^^^^^^^^^^ Gem `rubocop` requirements already given on line 2 of the Gemfile.
GEM
end
end
context 'and a duplicated gem is in a git/path/group/platforms block' do
it 'registers an offense' do
expect_offense(<<-GEM, 'Gemfile')
gem 'rubocop'
group :development do
gem 'rubocop', path: '/path/to/gem'
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Gem `rubocop` requirements already given on line 1 of the Gemfile.
end
GEM
end
end
context 'and the gem is conditionally duplicated' do
it 'does not register an offense' do
expect_no_offenses(<<-GEM, 'Gemfile')
if Dir.exist? local
gem 'rubocop', path: local
else
gem 'rubocop', '~> 0.90.0'
end
GEM
end
end
end
end