summaryrefslogtreecommitdiff
path: root/spec/rubocop/cop/gitlab/delegate_predicate_methods_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-04-20 23:50:22 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-04-20 23:50:22 +0000
commit9dc93a4519d9d5d7be48ff274127136236a3adb3 (patch)
tree70467ae3692a0e35e5ea56bcb803eb512a10bedb /spec/rubocop/cop/gitlab/delegate_predicate_methods_spec.rb
parent4b0f34b6d759d6299322b3a54453e930c6121ff0 (diff)
downloadgitlab-ce-9dc93a4519d9d5d7be48ff274127136236a3adb3.tar.gz
Add latest changes from gitlab-org/gitlab@13-11-stable-eev13.11.0-rc43
Diffstat (limited to 'spec/rubocop/cop/gitlab/delegate_predicate_methods_spec.rb')
-rw-r--r--spec/rubocop/cop/gitlab/delegate_predicate_methods_spec.rb40
1 files changed, 40 insertions, 0 deletions
diff --git a/spec/rubocop/cop/gitlab/delegate_predicate_methods_spec.rb b/spec/rubocop/cop/gitlab/delegate_predicate_methods_spec.rb
new file mode 100644
index 00000000000..1ceff0dd681
--- /dev/null
+++ b/spec/rubocop/cop/gitlab/delegate_predicate_methods_spec.rb
@@ -0,0 +1,40 @@
+# frozen_string_literal: true
+
+require 'fast_spec_helper'
+require_relative '../../../../rubocop/cop/gitlab/delegate_predicate_methods'
+
+RSpec.describe RuboCop::Cop::Gitlab::DelegatePredicateMethods do
+ subject(:cop) { described_class.new }
+
+ it 'registers offense for single predicate method with allow_nil:true' do
+ expect_offense(<<~SOURCE)
+ delegate :is_foo?, :do_foo, to: :bar, allow_nil: true
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Using `delegate` with `allow_nil` on the following predicate methods is discouraged: is_foo?.
+ SOURCE
+ end
+
+ it 'registers offense for multiple predicate methods with allow_nil:true' do
+ expect_offense(<<~SOURCE)
+ delegate :is_foo?, :is_bar?, to: :bar, allow_nil: true
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Using `delegate` with `allow_nil` on the following predicate methods is discouraged: is_foo?, is_bar?.
+ SOURCE
+ end
+
+ it 'registers no offense for non-predicate method with allow_nil:true' do
+ expect_no_offenses(<<~SOURCE)
+ delegate :do_foo, to: :bar, allow_nil: true
+ SOURCE
+ end
+
+ it 'registers no offense with predicate method with allow_nil:false' do
+ expect_no_offenses(<<~SOURCE)
+ delegate :is_foo?, to: :bar, allow_nil: false
+ SOURCE
+ end
+
+ it 'registers no offense with predicate method without allow_nil' do
+ expect_no_offenses(<<~SOURCE)
+ delegate :is_foo?, to: :bar
+ SOURCE
+ end
+end