/
memoized_helpers_in_example_group_spec.rb
64 lines (53 loc) · 1.68 KB
/
memoized_helpers_in_example_group_spec.rb
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# frozen_string_literal: true
RSpec.describe RuboCop::Cop::RSpec::MemoizedHelpersInExampleGroup do
subject(:cop) { described_class.new(config) }
let(:config) { RuboCop::Config.new }
# TODO: Write test code
#
# For example
it 'flags an offense when using `#let`' do
expect_offense(<<~RUBY)
let(:foo) { Foo.new }
^^^^^^^^^ Avoid using `let` – use a method call or local variable instead.
RUBY
end
it 'flags an offense when using `#subject` without name' do
expect_offense(<<~RUBY)
subject { Foo.new }
^^^^^^^ Avoid using `subject` – use a method call or local variable instead.
RUBY
end
it 'flags an offense when using `#subject` with name' do
expect_offense(<<~RUBY)
subject(:foo) { Foo.new }
^^^^^^^^^^^^^ Avoid using `subject` – use a method call or local variable instead.
RUBY
end
it 'does not flag an offense when using `#before`' do
expect_no_offenses(<<~RUBY)
before { foo }
RUBY
end
context 'when using AllowSubject configuration', :config do
subject(:cop) { described_class.new(config) }
let(:cop_config) do
{ 'AllowSubject' => true }
end
it 'flags an offense when using `#let`' do
expect_offense(<<~RUBY)
let(:foo) { Foo.new }
^^^^^^^^^ Avoid using `let` – use a method call or local variable instead.
RUBY
end
it 'does not flag an offense when using `#subject` without a name' do
expect_no_offenses(<<~RUBY)
subject { Foo.new }
RUBY
end
it 'does not flag an offense when using `#subject` with a name' do
expect_no_offenses(<<~RUBY)
subject(:foo) { Foo.new }
RUBY
end
end
end