blob: 03d7fc5e8b1e2efd6954a5d852a6b256fe5bafb1 (
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 'fast_spec_helper'
require 'rubocop'
require_relative '../../../../rubocop/cop/gitlab/finder_with_find_by'
RSpec.describe RuboCop::Cop::Gitlab::FinderWithFindBy do
subject(:cop) { described_class.new }
context 'when calling execute.find' do
it 'registers an offense and corrects' do
expect_offense(<<~CODE)
DummyFinder.new(some_args)
.execute
.find_by!(1)
^^^^^^^^ Don't chain finders `#execute` method with [...]
CODE
expect_correction(<<~CODE)
DummyFinder.new(some_args)
.find_by!(1)
CODE
end
context 'when called within the `FinderMethods` module' do
it 'does not register an offense' do
expect_no_offenses(<<~SRC)
module FinderMethods
def find_by!(*args)
execute.find_by!(args)
end
end
SRC
end
end
end
end
|