/
example_wording_spec.rb
180 lines (153 loc) · 4.04 KB
/
example_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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# frozen_string_literal: true
RSpec.describe RuboCop::Cop::RSpec::ExampleWording do
it 'ignores non-example blocks' do
expect_no_offenses('foo "should do something" do; end')
end
it 'finds description with `should` at the beginning' do
expect_offense(<<-RUBY)
it 'should do something' do
^^^^^^^^^^^^^^^^^^^ Do not use should when describing your tests.
end
RUBY
expect_correction(<<-RUBY)
it 'does something' do
end
RUBY
end
it 'finds interpolated description with `should` at the beginning' do
expect_offense(<<-'RUBY')
it "should do #{:stuff}" do
^^^^^^^^^^^^^^^^^^^ Do not use should when describing your tests.
end
RUBY
expect_correction(<<-'RUBY')
it "does #{:stuff}" do
end
RUBY
end
it 'finds description with `Should` at the beginning' do
expect_offense(<<-RUBY)
it 'Should do something' do
^^^^^^^^^^^^^^^^^^^ Do not use should when describing your tests.
end
RUBY
expect_correction(<<-RUBY)
it 'does something' do
end
RUBY
end
it 'finds description with `shouldn\'t` at the beginning' do
expect_offense(<<-RUBY)
it "shouldn't do something" do
^^^^^^^^^^^^^^^^^^^^^^ Do not use should when describing your tests.
end
RUBY
expect_correction(<<-RUBY)
it "does not do something" do
end
RUBY
end
it 'finds description with `SHOULDN\'T` at the beginning' do
expect_offense(<<-RUBY)
it "SHOULDN'T do something" do
^^^^^^^^^^^^^^^^^^^^^^ Do not use should when describing your tests.
end
RUBY
expect_correction(<<-RUBY)
it "DOES NOT do something" do
end
RUBY
end
it 'flags a lone should' do
expect_offense(<<-RUBY)
it 'should' do
^^^^^^ Do not use should when describing your tests.
end
RUBY
expect_correction(<<-RUBY)
it '' do
end
RUBY
end
it 'flags a lone should not' do
expect_offense(<<-RUBY)
it 'should not' do
^^^^^^^^^^ Do not use should when describing your tests.
end
RUBY
expect_correction(<<-RUBY)
it 'does not' do
end
RUBY
end
it 'finds leading its' do
expect_offense(<<-RUBY)
it "it does something" do
^^^^^^^^^^^^^^^^^ Do not repeat 'it' when describing your tests.
end
RUBY
expect_correction(<<-RUBY)
it "does something" do
end
RUBY
end
it 'finds leading it in interpolated description' do
expect_offense(<<-'RUBY')
it "it does #{action}" do
^^^^^^^^^^^^^^^^^ Do not repeat 'it' when describing your tests.
end
RUBY
expect_correction(<<-'RUBY')
it "does #{action}" do
end
RUBY
end
it "skips words beginning with 'it'" do
expect_no_offenses(<<-RUBY)
it 'itemizes items' do
end
RUBY
end
it 'skips descriptions without `should` at the beginning' do
expect_no_offenses(<<-RUBY)
it 'finds no should here' do
end
RUBY
end
it 'skips descriptions starting with words that begin with `should`' do
expect_no_offenses(<<-RUBY)
it 'shoulders the burden' do
end
RUBY
end
it 'skips interpolated description without literal `should` at the start' do
expect_no_offenses(<<-'RUBY')
it "#{should} not be here" do
end
RUBY
end
it 'flags \-separated multiline strings' do
expect_offense(<<-RUBY)
it 'should do something '\\
^^^^^^^^^^^^^^^^^^^^^^ Do not use should when describing your tests.
'and correctly fix' do
end
RUBY
expect_correction(<<-RUBY)
it 'does something and correctly fix' do
end
RUBY
end
it 'flags \-separated multiline interpolated strings' do
expect_offense(<<-'RUBY')
it "should do something "\
^^^^^^^^^^^^^^^^^^^^^^ Do not use should when describing your tests.
"with #{object}" do
end
RUBY
expect_correction(<<-'RUBY')
it "does something with #{object}" do
end
RUBY
end
end