forked from rubocop/rubocop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deprecated_attribute_assignment_spec.rb
99 lines (88 loc) · 3.27 KB
/
deprecated_attribute_assignment_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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# frozen_string_literal: true
RSpec.describe RuboCop::Cop::Gemspec::DeprecatedAttributeAssignment, :config do
shared_examples 'deprecated attributes' do |attribute, value|
it 'registers and corrects an offense when using `s.rubygems_version =`' do
expect_offense(<<~RUBY)
Gem::Specification.new do |s|
s.name = 'your_cool_gem_name'
s.#{attribute} = #{value}
^^^^^#{'^' * (attribute.size + value.size)} Do not set `#{attribute}` in gemspec.
s.bindir = 'exe'
end
RUBY
expect_correction(<<~RUBY)
Gem::Specification.new do |s|
s.name = 'your_cool_gem_name'
s.bindir = 'exe'
end
RUBY
end
it 'registers and corrects an offense when using `spec.rubygems_version =`' do
expect_offense(<<~RUBY)
Gem::Specification.new do |spec|
spec.name = 'your_cool_gem_name'
spec.#{attribute} = #{value}
^^^^^^^^#{'^' * (attribute.size + value.size)} Do not set `#{attribute}` in gemspec.
spec.bindir = 'exe'
end
RUBY
expect_correction(<<~RUBY)
Gem::Specification.new do |spec|
spec.name = 'your_cool_gem_name'
spec.bindir = 'exe'
end
RUBY
end
it 'does not register an offense when using `s.rubygems_version =` outside `Gem::Specification.new`' do
expect_no_offenses(<<~RUBY)
s.#{attribute} = #{value}
RUBY
end
it 'does not register an offense when using `rubygems_version =` and receiver is not `Gem::Specification.new` block variable' do
expect_no_offenses(<<~RUBY)
Gem::Specification.new do |spec|
s.#{attribute} = #{value}
end
RUBY
end
end
shared_examples 'deprecated attributes with addition' do |attribute, value|
it 'registers and corrects an offense when using `s.rubygems_version +=`' do
expect_offense(<<~RUBY)
Gem::Specification.new do |s|
s.name = 'your_cool_gem_name'
s.#{attribute} += #{value}
^^^^^^#{'^' * (attribute.size + value.size)} Do not set `#{attribute}` in gemspec.
s.bindir = 'exe'
end
RUBY
expect_correction(<<~RUBY)
Gem::Specification.new do |s|
s.name = 'your_cool_gem_name'
s.bindir = 'exe'
end
RUBY
end
it 'registers and corrects an offense when using `spec.rubygems_version +=`' do
expect_offense(<<~RUBY)
Gem::Specification.new do |spec|
spec.name = 'your_cool_gem_name'
spec.#{attribute} += #{value}
^^^^^^^^^#{'^' * (attribute.size + value.size)} Do not set `#{attribute}` in gemspec.
spec.bindir = 'exe'
end
RUBY
expect_correction(<<~RUBY)
Gem::Specification.new do |spec|
spec.name = 'your_cool_gem_name'
spec.bindir = 'exe'
end
RUBY
end
end
it_behaves_like 'deprecated attributes', 'date', "Time.now.strftime('%Y-%m-%d')"
it_behaves_like 'deprecated attributes', 'rubygems_version', '2.5'
it_behaves_like 'deprecated attributes', 'specification_version', '2.5'
it_behaves_like 'deprecated attributes', 'test_files', "Dir.glob('test/**/*')"
it_behaves_like 'deprecated attributes with addition', 'test_files', "Dir.glob('test/**/*')"
end