/
boolean_symbol_spec.rb
69 lines (57 loc) · 1.55 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
# frozen_string_literal: true
RSpec.describe RuboCop::Cop::Lint::BooleanSymbol, :config do
subject(:cop) { described_class.new(config) }
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
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
end