forked from rubocop/rubocop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
boolean_symbol_spec.rb
85 lines (71 loc) · 2.01 KB
/
boolean_symbol_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
# frozen_string_literal: true
RSpec.describe RuboCop::Cop::Lint::BooleanSymbol, :config do
it 'registers an offense when using `:true`' do
expect_offense(<<~RUBY)
:true
^^^^^ Symbol with a boolean name - you probably meant to use `true`.
RUBY
expect_correction(<<~RUBY)
true
RUBY
end
it 'registers an offense when using `:false`' do
expect_offense(<<~RUBY)
:false
^^^^^^ Symbol with a boolean name - you probably meant to use `false`.
RUBY
expect_correction(<<~RUBY)
false
RUBY
end
context 'when using the new hash syntax' do
it 'registers an offense when using `true:`' do
expect_offense(<<~RUBY)
{ true: 'Foo' }
^^^^ Symbol with a boolean name - you probably meant to use `true`.
RUBY
expect_correction(<<~RUBY)
{ true => 'Foo' }
RUBY
end
it 'registers an offense when using `false:`' do
expect_offense(<<~RUBY)
{ false: :bar }
^^^^^ Symbol with a boolean name - you probably meant to use `false`.
RUBY
expect_correction(<<~RUBY)
{ false => :bar }
RUBY
end
it 'registers an offense when using `key: :false`' do
expect_offense(<<~RUBY)
{ false: :false }
^^^^^^ Symbol with a boolean name - you probably meant to use `false`.
^^^^^ Symbol with a boolean name - you probably meant to use `false`.
RUBY
expect_correction(<<~RUBY)
{ false => false }
RUBY
end
end
it 'does not register an offense when using regular symbol' do
expect_no_offenses(<<~RUBY)
:something
RUBY
end
it 'does not register an offense when using `true`' do
expect_no_offenses(<<~RUBY)
true
RUBY
end
it 'does not register an offense when using `false`' do
expect_no_offenses(<<~RUBY)
false
RUBY
end
it 'does not register an offense when used inside percent-literal symbol array' do
expect_no_offenses(<<~RUBY)
%i[foo false]
RUBY
end
end