Skip to content

Commit 5d96600

Browse files
authored
Merge pull request #1990 from corsonknowles/continue_branch_coverage_quest
Complete branch coverage for more files
2 parents f96f5c5 + 9ca0da8 commit 5d96600

File tree

6 files changed

+85
-9
lines changed

6 files changed

+85
-9
lines changed

.rubocop_todo.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
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.68.0.
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:
10-
Exclude:
11-
- 'lib/rubocop/cop/rspec/multiple_expectations.rb'
12-
139
Rake/MethodDefinitionInTask:
1410
Exclude:
1511
- 'tasks/cut_release.rake'

.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: 97.43
5+
minimum_coverage line: 100, branch: 97.94
66
add_filter '/spec/'
77
add_filter '/vendor/bundle/'
88
end

lib/rubocop/rspec/hook.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def metadata
4545
private
4646

4747
def valid_scope?(node)
48-
node&.sym_type? && Language::HookScopes.all(node.value)
48+
node.sym_type? && Language::HookScopes.all(node.value)
4949
end
5050

5151
def transform_metadata(meta)

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/rspec/hook_spec.rb

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ def hook(source)
4545
.to be(:each)
4646
end
4747

48+
it 'ignores invalid hooks' do
49+
expect(hook('before(:invalid) { example_setup }').scope)
50+
.to be_nil
51+
end
52+
4853
it 'classifies :each as an example hook' do
4954
expect(hook('before(:each) { }').example?).to be(true)
5055
end
@@ -75,9 +80,13 @@ def metadata(source)
7580
end
7681

7782
if RUBY_VERSION >= '3.4'
83+
let(:expected_focus) { 's(:sym, :focus) => true' }
84+
let(:expected_invalid) { '{s(:sym, :invalid) => true}' }
7885
let(:expected_special) { 's(:sym, :special) => true' }
7986
let(:expected_symbol) { 's(:sym, :symbol) => true' }
8087
else
88+
let(:expected_focus) { 's(:sym, :focus)=>true' }
89+
let(:expected_invalid) { '{s(:sym, :invalid)=>true}' }
8190
let(:expected_special) { 's(:sym, :special)=>true' }
8291
let(:expected_symbol) { 's(:sym, :symbol)=>true' }
8392
end
@@ -103,8 +112,29 @@ def metadata(source)
103112
end
104113

105114
it 'withstands no arguments' do
106-
expect(metadata('before { foo }'))
107-
.to be_empty
115+
expect(metadata('before { foo }')).to be_empty
116+
end
117+
118+
it 'returns the symbol even when an invalid symbol scope is provided' do
119+
expect(metadata('before(:invalid) { foo }')).to eq(expected_invalid)
120+
end
121+
122+
it 'extracts multiple symbol metadata' do
123+
expect(metadata('before(:example, :special, :focus) { foo }'))
124+
.to eq("{#{expected_special}, #{expected_focus}}")
125+
end
126+
127+
it 'extracts multiple hash metadata' do
128+
expect(metadata('before(:example, special: true, focus: true) { foo }'))
129+
.to eq("{#{expected_special}, #{expected_focus}}")
130+
end
131+
132+
it 'combines multiple symbol and hash metadata' do
133+
expect(
134+
metadata(
135+
'before(:example, :symbol, special: true, focus: true) { foo }'
136+
)
137+
).to eq("{#{expected_symbol}, #{expected_special}, #{expected_focus}}")
108138
end
109139
end
110140
end

spec/rubocop/rspec/inject_spec.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# frozen_string_literal: true
2+
3+
RSpec.describe RuboCop::RSpec::Inject do
4+
describe '.defaults!' do
5+
let(:config_loader) { class_double(RuboCop::ConfigLoader).as_stubbed_const }
6+
7+
before do
8+
rubocop_config = instance_double(RuboCop::Config)
9+
allow(config_loader).to receive(:send)
10+
.with(:load_yaml_configuration, any_args)
11+
.and_return({})
12+
allow(RuboCop::Config).to receive(:new).and_return(rubocop_config)
13+
allow(config_loader).to receive(:merge_with_default)
14+
.and_return(rubocop_config)
15+
allow(config_loader).to receive(:instance_variable_set)
16+
end
17+
18+
context 'when ConfigLoader.debug? is true' do
19+
before do
20+
allow(config_loader).to receive(:debug?).and_return(true)
21+
end
22+
23+
it 'puts the configuration path' do
24+
expect { described_class.defaults! }.to output(
25+
%r{configuration from .*rubocop-rspec/config/default.yml}
26+
).to_stdout
27+
end
28+
end
29+
30+
context 'when ConfigLoader.debug? is false' do
31+
before do
32+
allow(config_loader).to receive(:debug?).and_return(false)
33+
end
34+
35+
it 'does not put the configuration path' do
36+
expect { described_class.defaults! }.not_to output.to_stdout
37+
end
38+
end
39+
end
40+
end

0 commit comments

Comments
 (0)