/
example_without_description_spec.rb
90 lines (77 loc) · 2.16 KB
/
example_without_description_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
# frozen_string_literal: true
RSpec.describe RuboCop::Cop::RSpec::ExampleWithoutDescription do
let(:cop_config) do
{ 'EnforcedStyle' => enforced_style }
end
context 'with EnforcedStyle `always_allow`' do
let(:enforced_style) { 'always_allow' }
it 'flags empty strings for description' do
expect_offense(<<-RUBY)
it '' do
^^ Omit the argument when you want to have auto-generated description.
expect(subject).to be_good
end
RUBY
end
it 'ignores `it` with a description' do
expect_no_offenses(<<-RUBY)
it 'is good' do
expect(subject).to be_good
end
RUBY
end
it 'ignores `it` without an argument' do
expect_no_offenses(<<-RUBY)
it do
expect(subject).to be_good
end
RUBY
end
end
context 'with EnforcedStyle `single_line_only`' do
let(:enforced_style) { 'single_line_only' }
it 'flags missing description in multi-line examples' do
expect_offense(<<-RUBY)
it do
^^ Add a description.
expect(subject).to be_good
end
RUBY
end
it 'ignores missing description in single-line examples' do
expect_no_offenses(<<-RUBY)
it { expect(subject).to be_good }
RUBY
end
it 'flags example with an empty string for description' do
expect_offense(<<-RUBY)
it('') { expect(subject).to be_good }
^^ Omit the argument when you want to have auto-generated description.
RUBY
end
end
context 'with EnforcedStyle `disallow`' do
let(:enforced_style) { 'disallow' }
it 'flags missing description in multi-line examples' do
expect_offense(<<-RUBY)
it do
^^ Add a description.
expect(subject).to be_good
end
RUBY
end
it 'flags missing description in single-line examples' do
expect_offense(<<-RUBY)
it { expect(subject).to be_good }
^^ Add a description.
RUBY
end
it 'ignores `it` with a description' do
expect_no_offenses(<<-RUBY)
it 'is good' do
expect(subject).to be_good
end
RUBY
end
end
end