forked from rubocop/rubocop-rspec
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
expect_in_hook_spec.rb
72 lines (64 loc) · 1.92 KB
/
expect_in_hook_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
65
66
67
68
69
70
71
72
# frozen_string_literal: true
RSpec.describe RuboCop::Cop::RSpec::ExpectInHook do
subject(:cop) { described_class.new }
it 'adds an offense for `expect` in `before` hook' do
expect_offense(<<-RUBY)
before do
expect(something).to eq('foo')
^^^^^^ Do not use `expect` in `before` hook
expect_any_instance_of(Something).to receive(:foo)
^^^^^^^^^^^^^^^^^^^^^^ Do not use `expect_any_instance_of` in `before` hook
end
RUBY
end
it 'adds an offense for `expect` in `after` hook' do
expect_offense(<<-RUBY)
after do
expect(something).to eq('foo')
^^^^^^ Do not use `expect` in `after` hook
expect_any_instance_of(Something).to receive(:foo)
^^^^^^^^^^^^^^^^^^^^^^ Do not use `expect_any_instance_of` in `after` hook
end
RUBY
end
it 'adds an offense for `expect` in `around` hook' do
expect_offense(<<-RUBY)
around do
expect(something).to eq('foo')
^^^^^^ Do not use `expect` in `around` hook
expect_any_instance_of(Something).to receive(:foo)
^^^^^^^^^^^^^^^^^^^^^^ Do not use `expect_any_instance_of` in `around` hook
end
RUBY
end
it 'adds an offense for `expect` with block in `before` hook' do
expect_offense(<<-RUBY)
before do
expect { something }.to eq('foo')
^^^^^^ Do not use `expect` in `before` hook
end
RUBY
end
it 'accepts an empty `before` hook' do
expect_no_offenses(<<-RUBY)
before do
end
RUBY
end
it 'accepts `allow` in `before` hook' do
expect_no_offenses(<<-RUBY)
before do
allow(something).to receive(:foo)
allow_any_instance_of(something).to receive(:foo)
end
RUBY
end
it 'accepts `expect` in `it`' do
expect_no_offenses(<<-RUBY)
it do
expect(something).to eq('foo')
expect_any_instance_of(something).to receive(:foo)
end
RUBY
end
end