Welcome to mirror list, hosted at ThFree Co, Russian Federation.

delegate_predicate_methods_spec.rb « gitlab « cop « rubocop « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1b497954aeed625f0e863bb7822601248ba0d495 (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
# frozen_string_literal: true

require 'rubocop_spec_helper'
require_relative '../../../../rubocop/cop/gitlab/delegate_predicate_methods'

RSpec.describe RuboCop::Cop::Gitlab::DelegatePredicateMethods do
  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