/
example_length_spec.rb
98 lines (88 loc) · 1.67 KB
/
example_length_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
93
94
95
96
97
98
# frozen_string_literal: true
RSpec.describe RuboCop::Cop::RSpec::ExampleLength do
let(:cop_config) { { 'Max' => 3 } }
it 'ignores non-spec blocks' do
expect_no_offenses(<<-RUBY)
foo do
line 1
line 2
line 3
line 4
end
RUBY
end
it 'allows an empty example' do
expect_no_offenses(<<-RUBY)
it do
end
RUBY
end
it 'allows a short example' do
expect_no_offenses(<<-RUBY)
it do
line 1
line 2
line 3
end
RUBY
end
it 'ignores comments' do
expect_no_offenses(<<-RUBY)
it do
line 1
line 2
# comment
line 3
end
RUBY
end
context 'when inspecting large examples' do
it 'flags the example' do
expect_offense(<<-RUBY)
it do
^^^^^ Example has too many lines. [4/3]
line 1
line 2
line 3
line 4
end
RUBY
end
end
context 'with CountComments enabled' do
let(:cop_config) do
{ 'Max' => 3, 'CountComments' => true }
end
it 'flags the example' do
expect_offense(<<-RUBY)
it do
^^^^^ Example has too many lines. [4/3]
line 1
line 2
# comment
line 3
end
RUBY
end
end
context 'when `CountAsOne` is not empty' do
before { cop_config['CountAsOne'] = ['array'] }
it 'folds array into one line' do
expect_no_offenses(<<~RUBY)
it do
a = 1
a = [
2,
3,
4,
5,
6,
7,
8,
9
]
end
RUBY
end
end
end