Skip to content

Commit e5898c1

Browse files
committed
Improve branch coverage
1 parent f5d9784 commit e5898c1

File tree

4 files changed

+56
-1
lines changed

4 files changed

+56
-1
lines changed

.simplecov

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
SimpleCov.start do
44
enable_coverage :branch
5-
minimum_coverage line: 100, branch: 96.79
5+
minimum_coverage line: 100, branch: 97.43
66
add_filter '/spec/'
77
add_filter '/vendor/bundle/'
88
end

spec/rubocop/cop/rspec/empty_line_after_subject_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@
1919
RUBY
2020
end
2121

22+
it 'does not register an offense outside of an example group' do
23+
expect_no_offenses(<<~RUBY)
24+
subject { foo }
25+
bar
26+
RUBY
27+
end
28+
2229
it 'registers an offense for empty line after subject!' do
2330
expect_offense(<<~RUBY)
2431
RSpec.describe User do

spec/rubocop/cop/rspec/leaky_constant_declaration_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ class SomeModule::AnotherModule::DummyClass
7373
end
7474
RUBY
7575
end
76+
77+
it 'ignores outside of example/shared group' do
78+
expect_no_offenses(<<~RUBY)
79+
class DummyClass
80+
end
81+
RUBY
82+
end
7683
end
7784

7885
describe 'module defined' do
@@ -85,5 +92,12 @@ module DummyModule
8592
end
8693
RUBY
8794
end
95+
96+
it 'ignores outside of example/shared group' do
97+
expect_no_offenses(<<~RUBY)
98+
module Dummymodule
99+
end
100+
RUBY
101+
end
88102
end
89103
end

spec/rubocop/cop/rspec/return_from_stub_spec.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,21 @@
176176
RUBY
177177
end
178178

179+
it 'registers, but does not try to autocorrect, heredocs' do
180+
expect_offense(<<~RUBY)
181+
it do
182+
allow(Foo).to receive(:bar) do
183+
^^ Use `and_return` for static values.
184+
<<-TXT
185+
You called me
186+
TXT
187+
end
188+
end
189+
RUBY
190+
191+
expect_no_corrections
192+
end
193+
179194
it 'does not register an offense for a stub without return value' do
180195
expect_no_offenses(<<~RUBY)
181196
it do
@@ -214,6 +229,19 @@ def stub_foo
214229
RUBY
215230
end
216231

232+
it 'registers, but does not try to autocorrect, heredocs' do
233+
expect_offense(<<~RUBY)
234+
it do
235+
allow(Foo).to receive(:bar).and_return(<<-TXT)
236+
^^^^^^^^^^ Use block for static values.
237+
You called me
238+
TXT
239+
end
240+
RUBY
241+
242+
expect_no_corrections
243+
end
244+
217245
it 'does not register an offense for dynamic values returned from method' do
218246
expect_no_offenses(<<~RUBY)
219247
it do
@@ -283,5 +311,11 @@ def stub_foo
283311
'me' }
284312
RUBY
285313
end
314+
315+
it 'ignores irrelevant #and_return methods' do
316+
expect_no_offenses(<<~RUBY)
317+
library.visit.and_return(book)
318+
RUBY
319+
end
286320
end
287321
end

0 commit comments

Comments
 (0)