diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 14:59:07 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 14:59:07 +0300 |
commit | 8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch) | |
tree | 544930fb309b30317ae9797a9683768705d664c4 /spec/rubocop/cop/gitlab | |
parent | 4b1de649d0168371549608993deac953eb692019 (diff) |
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'spec/rubocop/cop/gitlab')
-rw-r--r-- | spec/rubocop/cop/gitlab/policy_rule_boolean_spec.rb | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/spec/rubocop/cop/gitlab/policy_rule_boolean_spec.rb b/spec/rubocop/cop/gitlab/policy_rule_boolean_spec.rb new file mode 100644 index 00000000000..6221d038512 --- /dev/null +++ b/spec/rubocop/cop/gitlab/policy_rule_boolean_spec.rb @@ -0,0 +1,52 @@ +# frozen_string_literal: true + +require 'fast_spec_helper' +require 'rubocop' +require 'rubocop/rspec/support' +require_relative '../../../../rubocop/cop/gitlab/policy_rule_boolean' + +RSpec.describe RuboCop::Cop::Gitlab::PolicyRuleBoolean, type: :rubocop do + include CopHelper + + 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 |