-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
unified_integer_spec.rb
98 lines (83 loc) · 2.75 KB
/
unified_integer_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
# frozen_string_literal: true
RSpec.describe RuboCop::Cop::Lint::UnifiedInteger, :config do
shared_examples 'registers an offense' do |klass|
context 'target ruby version < 2.4', :ruby23 do
context "when #{klass}" do
context 'without any decorations' do
it 'registers an offense and autocorrects' do
expect_offense(<<~RUBY, klass: klass)
1.is_a?(%{klass})
^{klass} Use `Integer` instead of `#{klass}`.
RUBY
expect_no_corrections
end
end
context 'when explicitly specified as toplevel constant' do
let(:source) { "1.is_a?(::#{klass})" }
it 'registers an offense' do
expect_offense(<<~RUBY, klass: klass)
1.is_a?(::%{klass})
^^^{klass} Use `Integer` instead of `#{klass}`.
RUBY
expect_no_corrections
end
end
context 'with MyNamespace' do
it 'does not register an offense' do
expect_no_offenses("1.is_a?(MyNamespace::#{klass})")
end
end
end
end
context 'target ruby version >= 2.4', :ruby24 do
context "when #{klass}" do
context 'without any decorations' do
it 'registers an offense' do
expect_offense(<<~RUBY, klass: klass)
1.is_a?(#{klass})
^{klass} Use `Integer` instead of `#{klass}`.
RUBY
expect_correction(<<~RUBY)
1.is_a?(Integer)
RUBY
end
end
context 'when explicitly specified as toplevel constant' do
it 'registers an offense' do
expect_offense(<<~RUBY, klass: klass)
1.is_a?(::#{klass})
^^^{klass} Use `Integer` instead of `#{klass}`.
RUBY
expect_correction(<<~RUBY)
1.is_a?(::Integer)
RUBY
end
end
context 'with MyNamespace' do
it 'does not register an offense' do
expect_no_offenses("1.is_a?(MyNamespace::#{klass})")
end
end
end
end
end
include_examples 'registers an offense', 'Fixnum'
include_examples 'registers an offense', 'Bignum'
context 'when Integer' do
context 'without any decorations' do
it 'does not register an offense' do
expect_no_offenses('1.is_a?(Integer)')
end
end
context 'when explicitly specified as toplevel constant' do
it 'does not register an offense' do
expect_no_offenses('1.is_a?(::Integer)')
end
end
context 'with MyNamespace' do
it 'does not register an offense' do
expect_no_offenses('1.is_a?(MyNamespace::Integer)')
end
end
end
end