blob: f73fc71b6016d0c6aa6e473691c584ee3a47b7ea (
plain)
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
|
# frozen_string_literal: true
require 'fast_spec_helper'
require_relative '../../../../rubocop/cop/gitlab/policy_rule_boolean'
RSpec.describe RuboCop::Cop::Gitlab::PolicyRuleBoolean do
subject(:cop) { described_class.new }
it 'registers offense for &&' do
expect_offense(<<~SOURCE)
rule { conducts_electricity && batteries }.enable :light_bulb
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ && is not allowed within a rule block. Did you mean to use `&`?
SOURCE
end
it 'registers offense for ||' do
expect_offense(<<~SOURCE)
rule { conducts_electricity || batteries }.enable :light_bulb
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ || is not allowed within a rule block. Did you mean to use `|`?
SOURCE
end
it 'registers offense for if' do
expect_offense(<<~SOURCE)
rule { if conducts_electricity then can?(:magnetize) else batteries end }.enable :motor
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ if and ternary operators are not allowed within a rule block.
SOURCE
end
it 'registers offense for ternary operator' do
expect_offense(<<~SOURCE)
rule { conducts_electricity ? can?(:magnetize) : batteries }.enable :motor
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ if and ternary operators are not allowed within a rule block.
SOURCE
end
it 'registers no offense for &' do
expect_no_offenses(<<~SOURCE)
rule { conducts_electricity & batteries }.enable :light_bulb
SOURCE
end
it 'registers no offense for |' do
expect_no_offenses(<<~SOURCE)
rule { conducts_electricity | batteries }.enable :light_bulb
SOURCE
end
end
|