blob: cee593fe5357b9cd8c1df3aaba8552d846a2efe1 (
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
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# frozen_string_literal: true
require 'spec_helper'
require_relative '../../../../rubocop/cop/rspec/empty_line_after_shared_example'
describe RuboCop::Cop::RSpec::EmptyLineAfterSharedExample do
subject(:cop) { described_class.new }
it 'flags a missing empty line after `it_behaves_like` block' do
expect_offense(<<-RUBY)
RSpec.describe Foo do
it_behaves_like 'does this' do
end
^^^ Add an empty line after `it_behaves_like` block.
it_behaves_like 'does that' do
end
end
RUBY
expect_correction(<<-RUBY)
RSpec.describe Foo do
it_behaves_like 'does this' do
end
it_behaves_like 'does that' do
end
end
RUBY
end
it 'ignores one-line shared examples before shared example blocks' do
expect_no_offenses(<<-RUBY)
RSpec.describe Foo do
it_behaves_like 'does this'
it_behaves_like 'does that' do
end
end
RUBY
end
it 'flags a missing empty line after `shared_examples`' do
expect_offense(<<-RUBY)
RSpec.context 'foo' do
shared_examples do
end
^^^ Add an empty line after `shared_examples` block.
shared_examples 'something gets done' do
end
end
RUBY
expect_correction(<<-RUBY)
RSpec.context 'foo' do
shared_examples do
end
shared_examples 'something gets done' do
end
end
RUBY
end
it 'ignores consecutive one-liners' do
expect_no_offenses(<<-RUBY)
RSpec.describe Foo do
it_behaves_like 'do this'
it_behaves_like 'do that'
end
RUBY
end
it 'flags mixed one-line and multi-line shared examples' do
expect_offense(<<-RUBY)
RSpec.context 'foo' do
it_behaves_like 'do this'
it_behaves_like 'do that'
it_behaves_like 'does this' do
end
^^^ Add an empty line after `it_behaves_like` block.
it_behaves_like 'do this'
it_behaves_like 'do that'
end
RUBY
end
end
|