2021-02-22 17:27:13 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
require 'rubocop_spec_helper'
|
2021-02-22 17:27:13 +05:30
|
|
|
require_relative '../../../../rubocop/cop/gitlab/policy_rule_boolean'
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
RSpec.describe RuboCop::Cop::Gitlab::PolicyRuleBoolean do
|
2021-02-22 17:27:13 +05:30
|
|
|
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
|