-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
required_ruby_version_spec.rb
79 lines (72 loc) · 2.79 KB
/
required_ruby_version_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
# frozen_string_literal: true
RSpec.describe RuboCop::Cop::Gemspec::RequiredRubyVersion, :config do
context 'target ruby version > 2.7', :ruby27 do
it 'registers an offense when `required_ruby_version` is lower than ' \
'`TargetRubyVersion`' do
expect_offense(<<~RUBY, '/path/to/foo.gemspec')
Gem::Specification.new do |spec|
spec.required_ruby_version = '>= 2.6.0'
^^^^^^^^^^ `required_ruby_version` (2.6, declared in foo.gemspec) and `TargetRubyVersion` (2.7, which may be specified in .rubocop.yml) should be equal.
end
RUBY
end
describe 'false negatives' do
it 'does not register an offense when `required_ruby_version` ' \
'is assigned as a variable (string literal)' do
expect_no_offenses(<<~RUBY)
Gem::Specification.new do |spec|
version = '>= 2.6.0'
spec.required_ruby_version = version
end
RUBY
end
it 'does not register an offense when `required_ruby_version` ' \
'is assigned as a variable (an array of string literal)' do
expect_no_offenses(<<~RUBY)
Gem::Specification.new do |spec|
lowest_version = '>= 2.6.0'
highest_version = '< 2.8.0'
spec.required_ruby_version = [lowest_version, highest_version]
end
RUBY
end
end
end
context 'target ruby version > 2.5', :ruby25 do
it 'registers an offense when `required_ruby_version` is higher than ' \
'`TargetRubyVersion`' do
expect_offense(<<~RUBY, '/path/to/bar.gemspec')
Gem::Specification.new do |spec|
spec.required_ruby_version = '>= 2.6.0'
^^^^^^^^^^ `required_ruby_version` (2.6, declared in bar.gemspec) and `TargetRubyVersion` (2.5, which may be specified in .rubocop.yml) should be equal.
end
RUBY
end
end
context 'target ruby version > 2.6', :ruby26 do
it 'does not register an offense when `required_ruby_version` equals ' \
'`TargetRubyVersion`' do
expect_no_offenses(<<~RUBY)
Gem::Specification.new do |spec|
spec.required_ruby_version = '>= 2.6.0'
end
RUBY
end
it 'does not register an offense when `required_ruby_version` ' \
'(omit patch version) equals `TargetRubyVersion`' do
expect_no_offenses(<<~RUBY)
Gem::Specification.new do |spec|
spec.required_ruby_version = '>= 2.6'
end
RUBY
end
it 'does not register an offense when lowest version of ' \
'`required_ruby_version` equals `TargetRubyVersion`' do
expect_no_offenses(<<~RUBY)
Gem::Specification.new do |spec|
spec.required_ruby_version = ['>= 2.6.0', '< 2.8.0']
end
RUBY
end
end
end