Skip to content

Commit 2ff8b66

Browse files
committed
Complete branch coverage for 4 more files.
1 parent f5d9784 commit 2ff8b66

File tree

6 files changed

+69
-5
lines changed

6 files changed

+69
-5
lines changed

.rubocop_todo.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config --no-offense-counts --no-auto-gen-timestamp`
3-
# using RuboCop version 1.63.4.
3+
# using RuboCop version 1.66.1.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

9-
Lint/ToEnumArguments:
9+
# This cop supports safe autocorrection (--autocorrect).
10+
InternalAffairs/RedundantMessageArgument:
1011
Exclude:
11-
- 'lib/rubocop/cop/rspec/multiple_expectations.rb'
12+
- 'lib/rubocop/cop/rspec/context_wording.rb'
1213

1314
Rake/MethodDefinitionInTask:
1415
Exclude:

.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.3
66
add_filter '/spec/'
77
add_filter '/vendor/bundle/'
88
end

spec/rubocop/cop/rspec/empty_line_after_subject_spec.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
RSpec.describe RuboCop::Cop::RSpec::EmptyLineAfterSubject do
3+
RSpec.describe RuboCop::Cop::RSpec::EmptyLineAfterSubject, :config do
44
it 'registers an offense for empty line after subject' do
55
expect_offense(<<~RUBY)
66
RSpec.describe User do
@@ -211,4 +211,13 @@
211211
end
212212
RUBY
213213
end
214+
215+
it 'ignores subject outside of example group' do
216+
expect_no_offenses(<<~RUBY)
217+
subject(:foo) { bar }
218+
describe 'example group' do
219+
# ...
220+
end
221+
RUBY
222+
end
214223
end

spec/rubocop/cop/rspec/instance_spy_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@
4444
end
4545
RUBY
4646
end
47+
48+
it 'ignores instance_double when expect is called on another variable' do
49+
expect_no_offenses(<<~RUBY)
50+
it do
51+
foo = instance_double(Foo).as_null_object
52+
bar = instance_spy(Bar).as_null_object
53+
expect(bar).to have_received(:baz)
54+
end
55+
RUBY
56+
end
4757
end
4858

4959
context 'when not used with `have_received`' do

spec/rubocop/cop/rspec/stubbed_mock_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,23 @@
134134
.with(bar).and_return baz
135135
RUBY
136136
end
137+
138+
describe '#replacement', :config do
139+
it 'returns "allow" for :expect' do
140+
expect(cop.send(:replacement, :expect)).to eq(:allow)
141+
end
142+
143+
it 'returns "allow(subject)" for :is_expected' do
144+
expect(cop.send(:replacement, :is_expected)).to eq('allow(subject)')
145+
end
146+
147+
it 'returns "allow_any_instance_of" for :expect_any_instance_of' do
148+
expect(cop.send(:replacement,
149+
:expect_any_instance_of)).to eq(:allow_any_instance_of)
150+
end
151+
152+
it 'falls through silently and returns nil for unknown methods' do
153+
expect(cop.send(:replacement, :unknown_method)).to be_nil
154+
end
155+
end
137156
end

spec/rubocop/rspec/config_formatter_spec.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,29 @@
6464
Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Baz
6565
YAML
6666
end
67+
68+
describe '#unified_config' do
69+
context 'when cop is in SUBDEPARTMENTS or AMENDMENTS' do
70+
let(:config) do
71+
{ 'RSpec/SubDepartment' => {}, 'Metrics/BlockLength' => {} }
72+
end
73+
let(:descriptions) do
74+
{ 'RSpec/SubDepartment' => {}, 'Metrics/BlockLength' => {} }
75+
end
76+
77+
before do
78+
stub_const('RuboCop::RSpec::ConfigFormatter::SUBDEPARTMENTS',
79+
['RSpec/SubDepartment'])
80+
stub_const('RuboCop::RSpec::ConfigFormatter::AMENDMENTS',
81+
['Metrics/BlockLength'])
82+
end
83+
84+
it 'skips processing for those cops' do
85+
formatter = described_class.new(config, descriptions)
86+
unified_config = formatter.send(:unified_config)
87+
expect(unified_config['RSpec/SubDepartment']).to eq({})
88+
expect(unified_config['Metrics/BlockLength']).to eq({})
89+
end
90+
end
91+
end
6792
end

0 commit comments

Comments
 (0)