/
before_after_all_spec.rb
50 lines (45 loc) · 1.38 KB
/
before_after_all_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
# frozen_string_literal: true
RSpec.describe RuboCop::Cop::RSpec::BeforeAfterAll do
def message(hook)
"Beware of using `#{hook}` as it may cause state to leak between tests. "\
'If you are using `rspec-rails`, and `use_transactional_fixtures` is '\
"enabled, then records created in `#{hook}` are not automatically rolled "\
'back.'
end
context 'when using before all' do
it 'registers an offense' do
expect_offense(<<-RUBY)
before(:all) { do_something }
^^^^^^^^^^^^ #{message('before(:all)')}
before(:context) { do_something }
^^^^^^^^^^^^^^^^ #{message('before(:context)')}
RUBY
end
end
context 'when using after all' do
it 'registers an offense' do
expect_offense(<<-RUBY)
after(:all) { do_something }
^^^^^^^^^^^ #{message('after(:all)')}
after(:context) { do_something }
^^^^^^^^^^^^^^^ #{message('after(:context)')}
RUBY
end
end
context 'when using before each' do
it 'does not register an offense' do
expect_no_offenses(<<-RUBY)
before(:each) { do_something }
before(:example) { do_something }
RUBY
end
end
context 'when using after each' do
it 'does not register an offense' do
expect_no_offenses(<<-RUBY)
after(:each) { do_something }
after(:example) { do_something }
RUBY
end
end
end