Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve branch coverage #1989

Merged
merged 1 commit into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .simplecov
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

SimpleCov.start do
enable_coverage :branch
minimum_coverage line: 100, branch: 96.79
minimum_coverage line: 100, branch: 97.43
add_filter '/spec/'
add_filter '/vendor/bundle/'
end
7 changes: 7 additions & 0 deletions spec/rubocop/cop/rspec/empty_line_after_subject_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
RUBY
end

it 'does not register an offense outside of an example group' do
expect_no_offenses(<<~RUBY)
subject { foo }
bar
RUBY
end

it 'registers an offense for empty line after subject!' do
expect_offense(<<~RUBY)
RSpec.describe User do
Expand Down
14 changes: 14 additions & 0 deletions spec/rubocop/cop/rspec/leaky_constant_declaration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ class SomeModule::AnotherModule::DummyClass
end
RUBY
end

it 'ignores outside of example/shared group' do
expect_no_offenses(<<~RUBY)
class DummyClass
end
RUBY
end
end

describe 'module defined' do
Expand All @@ -85,5 +92,12 @@ module DummyModule
end
RUBY
end

it 'ignores outside of example/shared group' do
expect_no_offenses(<<~RUBY)
module Dummymodule
end
RUBY
end
end
end
34 changes: 34 additions & 0 deletions spec/rubocop/cop/rspec/return_from_stub_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,21 @@
RUBY
end

it 'registers, but does not try to autocorrect, heredocs' do
expect_offense(<<~RUBY)
it do
allow(Foo).to receive(:bar) do
^^ Use `and_return` for static values.
<<-TXT
You called me
TXT
end
end
RUBY

expect_no_corrections
end

it 'does not register an offense for a stub without return value' do
expect_no_offenses(<<~RUBY)
it do
Expand Down Expand Up @@ -214,6 +229,19 @@ def stub_foo
RUBY
end

it 'registers, but does not try to autocorrect, heredocs' do
expect_offense(<<~RUBY)
it do
allow(Foo).to receive(:bar).and_return(<<-TXT)
^^^^^^^^^^ Use block for static values.
You called me
TXT
end
RUBY

expect_no_corrections
end

it 'does not register an offense for dynamic values returned from method' do
expect_no_offenses(<<~RUBY)
it do
Expand Down Expand Up @@ -283,5 +311,11 @@ def stub_foo
'me' }
RUBY
end

it 'ignores irrelevant #and_return methods' do
expect_no_offenses(<<~RUBY)
library.visit.and_return(book)
RUBY
end
end
end