Skip to content

Commit 29d75a3

Browse files
committed
More RepeatedDescription and Example specs
1 parent 2362e2a commit 29d75a3

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

spec/rubocop/cop/rspec/repeated_description_spec.rb

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,40 @@
146146
RUBY
147147
end
148148

149+
it 'registers offense for repeated description in different iterators' do
150+
expect_offense(<<-RUBY)
151+
describe 'doing x' do
152+
%i[foo bar].each do |type|
153+
it "does a thing \#{type}" do
154+
^^^^^^^^^^^^^^^^^^^^^^^^^ Don't repeat descriptions within an example group.
155+
end
156+
end
157+
158+
%i[baz qux].each do |type|
159+
it "does a thing \#{type}" do
160+
^^^^^^^^^^^^^^^^^^^^^^^^^ Don't repeat descriptions within an example group.
161+
end
162+
end
163+
end
164+
RUBY
165+
end
166+
167+
it 'does not flag different descriptions in different iterators' do
168+
expect_no_offenses(<<-RUBY)
169+
describe 'doing x' do
170+
%i[foo bar].each do |type|
171+
it "does a thing \#{type}" do
172+
end
173+
end
174+
175+
%i[baz qux].each do |type|
176+
it "does another thing \#{type}" do
177+
end
178+
end
179+
end
180+
RUBY
181+
end
182+
149183
it 'registers offense if same method used in docstring' do
150184
expect_offense(<<-RUBY)
151185
describe 'doing x' do
@@ -161,4 +195,18 @@
161195
end
162196
RUBY
163197
end
198+
199+
it 'does not flag different methods used as docstring' do
200+
expect_no_offenses(<<-RUBY)
201+
describe 'doing x' do
202+
it(description) do
203+
# ...
204+
end
205+
206+
it(title) do
207+
# ...
208+
end
209+
end
210+
RUBY
211+
end
164212
end

spec/rubocop/rspec/example_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ def example(source)
2222
.to eq(s(:dstr, s(:str, 'does '), s(:begin, s(:send, nil, :x))))
2323
end
2424

25+
it 'extracts symbol doc string' do
26+
expect(example('it(:works_fine)').doc_string)
27+
.to eq(s(:sym, :works_fine))
28+
end
29+
2530
it 'extracts method doc string' do
2631
expect(example('it(description)').doc_string)
2732
.to eq(s(:send, nil, :description))

0 commit comments

Comments
 (0)