forked from rubocop/rubocop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unless_multiple_conditions_spec.rb
52 lines (45 loc) · 1.29 KB
/
unless_multiple_conditions_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
# frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::UnlessMultipleConditions do
subject(:cop) { described_class.new(config) }
let(:config) { RuboCop::Config.new }
it 'registers an offense when using `unless`' \
'with multiple `and` conditions' do
expect_offense(<<-RUBY.strip_indent)
unless foo && bar
^^^^^^^^^^ Avoid using `unless` with multiple conditions.
something
end
RUBY
end
it 'registers an offense when using `unless` with multiple `or` conditions' do
expect_offense(<<-RUBY.strip_indent)
unless foo || bar
^^^^^^^^^^ Avoid using `unless` with multiple conditions.
something
end
RUBY
end
it 'does not register an offense when using `if`' \
'with multiple `and` conditions' do
expect_no_offenses(<<-RUBY.strip_indent)
if !foo && !bar
something
end
RUBY
end
it 'does not register an offense when using `if`' \
'with multiple `or` conditions' do
expect_no_offenses(<<-RUBY.strip_indent)
if !foo || !bar
something
end
RUBY
end
it 'does not register an offense when using `unless` with single condition' do
expect_no_offenses(<<-RUBY.strip_indent)
unless foo
something
end
RUBY
end
end