forked from rubocop/rubocop-rspec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
context_wording_spec.rb
92 lines (80 loc) · 2.61 KB
/
context_wording_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::ContextWording, :config do
let(:cop_config) { { 'Prefixes' => %w[when with] } }
it 'skips describe blocks' do
expect_no_offenses(<<-RUBY)
describe 'the display name not present' do
end
RUBY
end
it 'finds context without `when` at the beginning' do
expect_offense(<<-RUBY)
context 'the display name not present' do
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Start context description with 'when', or 'with'.
end
RUBY
end
it 'finds shared_context without `when` at the beginning' do
expect_offense(<<-RUBY)
shared_context 'the display name not present' do
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Start context description with 'when', or 'with'.
end
RUBY
end
it "skips descriptions beginning with 'when'" do
expect_no_offenses(<<-RUBY)
context 'when the display name is not present' do
end
RUBY
end
it 'finds context without separate `when` at the beginning' do
expect_offense(<<-RUBY)
context 'whenever you do' do
^^^^^^^^^^^^^^^^^ Start context description with 'when', or 'with'.
end
RUBY
end
context 'with metadata hash' do
it 'finds context without separate `when` at the beginning' do
expect_offense(<<-RUBY)
context 'whenever you do', legend: true do
^^^^^^^^^^^^^^^^^ Start context description with 'when', or 'with'.
end
RUBY
end
end
context 'with symbol metadata' do
it 'finds context without separate `when` at the beginning' do
expect_offense(<<-RUBY)
context 'whenever you do', :legend do
^^^^^^^^^^^^^^^^^ Start context description with 'when', or 'with'.
end
RUBY
end
end
context 'with mixed metadata' do
it 'finds context without separate `when` at the beginning' do
expect_offense(<<-RUBY)
context 'whenever you do', :legend, myth: true do
^^^^^^^^^^^^^^^^^ Start context description with 'when', or 'with'.
end
RUBY
end
end
context 'when configured' do
let(:cop_config) { { 'Prefixes' => %w[if] } }
it 'finds context without allowed prefixes at the beginning' do
expect_offense(<<-RUBY)
context 'when display name is present' do
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Start context description with 'if'.
end
RUBY
end
it 'skips descriptions with allowed prefixes at the beginning' do
expect_no_offenses(<<-RUBY)
context 'if display name is present' do
end
RUBY
end
end
end