/
empty_line_after_subject_spec.rb
92 lines (78 loc) · 2.06 KB
/
empty_line_after_subject_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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# frozen_string_literal: true
RSpec.describe RuboCop::Cop::RSpec::EmptyLineAfterSubject do
it 'checks for empty line after subject' do
expect_offense(<<-RUBY)
RSpec.describe User do
subject { described_class.new }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Add an empty line after `subject`.
let(:params) { foo }
end
RUBY
expect_correction(<<-RUBY)
RSpec.describe User do
subject { described_class.new }
let(:params) { foo }
end
RUBY
end
it 'checks for empty line after subject!' do
expect_offense(<<-RUBY)
RSpec.describe User do
subject! { described_class.new }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Add an empty line after `subject!`.
let(:params) { foo }
end
RUBY
expect_correction(<<-RUBY)
RSpec.describe User do
subject! { described_class.new }
let(:params) { foo }
end
RUBY
end
it 'approves empty line after subject' do
expect_no_offenses(<<-RUBY)
RSpec.describe User do
subject { described_class.new }
let(:params) { foo }
end
RUBY
end
it 'approves empty line after subject!' do
expect_no_offenses(<<-RUBY)
RSpec.describe User do
subject! { described_class.new }
let(:params) { foo }
end
RUBY
end
it 'handles subjects in tests' do
expect_no_offenses(<<-RUBY)
RSpec.describe User do
# This shouldn't really ever happen in a sane codebase but I still
# want to avoid false positives
it "doesn't mind me calling a method called subject in the test" do
subject { bar }
let(foo)
end
end
RUBY
end
it 'handles multiline subject block' do
expect_no_offenses(<<-RUBY)
RSpec.describe User do
subject do
described_class.new
end
let(:params) { foo }
end
RUBY
end
it 'handles subject being the latest node' do
expect_no_offenses(<<-RUBY)
RSpec.describe User do
subject { described_user }
end
RUBY
end
end