Skip to content

Commit

Permalink
Complete branch coverage for more files
Browse files Browse the repository at this point in the history
  • Loading branch information
corsonknowles committed Oct 27, 2024
1 parent e80d28c commit 88b07e7
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 4 deletions.
7 changes: 4 additions & 3 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# This configuration was generated by
# `rubocop --auto-gen-config --no-offense-counts --no-auto-gen-timestamp`
# using RuboCop version 1.63.4.
# using RuboCop version 1.66.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

Lint/ToEnumArguments:
# This cop supports safe autocorrection (--autocorrect).
InternalAffairs/RedundantMessageArgument:
Exclude:
- 'lib/rubocop/cop/rspec/multiple_expectations.rb'
- 'lib/rubocop/cop/rspec/context_wording.rb'

Rake/MethodDefinitionInTask:
Exclude:
Expand Down
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: 97.43
minimum_coverage line: 100, branch: 97.81
add_filter '/spec/'
add_filter '/vendor/bundle/'
end
10 changes: 10 additions & 0 deletions spec/rubocop/cop/rspec/instance_spy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@
end
RUBY
end

it 'ignores instance_double when expect is called on another variable' do
expect_no_offenses(<<~RUBY)
it do
foo = instance_double(Foo).as_null_object
bar = instance_spy(Bar).as_null_object
expect(bar).to have_received(:baz)
end
RUBY
end
end

context 'when not used with `have_received`' do
Expand Down
19 changes: 19 additions & 0 deletions spec/rubocop/cop/rspec/stubbed_mock_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,23 @@
.with(bar).and_return baz
RUBY
end

describe '#replacement', :config do
it 'returns "allow" for :expect' do
expect(cop.send(:replacement, :expect)).to eq(:allow)
end

it 'returns "allow(subject)" for :is_expected' do
expect(cop.send(:replacement, :is_expected)).to eq('allow(subject)')
end

it 'returns "allow_any_instance_of" for :expect_any_instance_of' do
expect(cop.send(:replacement,
:expect_any_instance_of)).to eq(:allow_any_instance_of)
end

it 'falls through silently and returns nil for unknown methods' do
expect(cop.send(:replacement, :unknown_method)).to be_nil
end
end
end
25 changes: 25 additions & 0 deletions spec/rubocop/rspec/config_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,29 @@
Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Baz
YAML
end

describe '#unified_config' do
context 'when cop is in SUBDEPARTMENTS or AMENDMENTS' do
let(:config) do
{ 'RSpec/SubDepartment' => {}, 'Metrics/BlockLength' => {} }
end
let(:descriptions) do
{ 'RSpec/SubDepartment' => {}, 'Metrics/BlockLength' => {} }
end

before do
stub_const('RuboCop::RSpec::ConfigFormatter::SUBDEPARTMENTS',
['RSpec/SubDepartment'])
stub_const('RuboCop::RSpec::ConfigFormatter::AMENDMENTS',
['Metrics/BlockLength'])
end

it 'skips processing for those cops' do
formatter = described_class.new(config, descriptions)
unified_config = formatter.send(:unified_config)
expect(unified_config['RSpec/SubDepartment']).to eq({})
expect(unified_config['Metrics/BlockLength']).to eq({})
end
end
end
end

0 comments on commit 88b07e7

Please sign in to comment.