Skip to content

Commit 1e3e292

Browse files
committed
Adopt rubocop-rspec plugin
1 parent ad52a12 commit 1e3e292

32 files changed

Lines changed: 1029 additions & 948 deletions

.rubocop.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ plugins:
22
- rubocop-capybara
33
- rubocop-performance
44
- rubocop-rake
5+
- rubocop-rspec
56

67
AllCops:
78
Exclude:
@@ -106,6 +107,42 @@ Naming/FileName:
106107
- "spec/fixtures/utf-8.rb"
107108
- "lib/simplecov-html.rb"
108109

110+
inherit_mode:
111+
merge:
112+
- Exclude
113+
114+
# Spec fixtures are byte-stable test inputs (line numbers and `puts`
115+
# statements matter for coverage assertions), and spec/support/ holds
116+
# helper modules — neither directory is a real spec suite, so the
117+
# RSpec department shouldn't touch them. (The fixture rspec runners
118+
# under spec/fixtures/frameworks/ are intentionally minimal:
119+
# `expect(1).to eq(2)` is the point.)
120+
RSpec:
121+
Exclude:
122+
- "spec/fixtures/**/*"
123+
- "spec/support/**/*"
124+
RSpec/ExpectActual:
125+
Exclude:
126+
- "spec/fixtures/**/*"
127+
RSpec/DescribeClass:
128+
Exclude:
129+
- "spec/fixtures/**/*"
130+
131+
RSpec/ExampleLength:
132+
Max: 20 # TODO: Lower to 5
133+
RSpec/MultipleExpectations:
134+
Max: 6 # TODO: Lower to 1
135+
RSpec/SpecFilePathFormat:
136+
# The project layout puts simplecov specs at spec/foo_spec.rb (mirroring
137+
# lib/simplecov/foo.rb) rather than spec/simple_cov/foo_spec.rb. Map the
138+
# SimpleCov module to an empty path segment so the cop accepts that.
139+
CustomTransform:
140+
SimpleCov: ''
141+
RSpec/NestedGroups:
142+
Max: 5 # TODO: Lower to 3
143+
RSpec/MultipleMemoizedHelpers:
144+
Max: 11 # TODO: Lower to 5
145+
109146
Style/CollectionMethods:
110147
Description: Enforces the use of consistent method names from the Enumerable module.
111148
PreferredMethods:

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ group :development do
1616
gem "rubocop-capybara"
1717
gem "rubocop-performance"
1818
gem "rubocop-rake"
19+
gem "rubocop-rspec"
1920
end
2021
gem "test-unit"
2122
# Explicitly add webrick because it has been removed from stdlib in Ruby 3.0

Gemfile.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ GEM
165165
rubocop-rake (0.7.1)
166166
lint_roller (~> 1.1)
167167
rubocop (>= 1.72.1)
168+
rubocop-rspec (3.9.0)
169+
lint_roller (~> 1.1)
170+
rubocop (~> 1.81)
168171
ruby-progressbar (1.13.0)
169172
stringio (3.2.0)
170173
sys-uname (1.5.1)
@@ -208,6 +211,7 @@ DEPENDENCIES
208211
rubocop-capybara
209212
rubocop-performance
210213
rubocop-rake
214+
rubocop-rspec
211215
simplecov!
212216
test-unit
213217
webrick

spec/combine/results_combiner_spec.rb

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
describe SimpleCov::Combine::ResultsCombiner do
66
describe "with two faked coverage resultsets" do
7-
let(:resultset1) do
7+
let(:first_resultset) do
88
{
99
source_fixture("sample.rb") => {
1010
"lines" => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil],
@@ -22,7 +22,7 @@
2222
}
2323
end
2424

25-
let(:resultset2) do
25+
let(:second_resultset) do
2626
{
2727
source_fixture("sample.rb") => {"lines" => [1, nil, 1, 1, nil, nil, 1, 1, nil, nil]},
2828
source_fixture("app/models/user.rb") => {
@@ -37,7 +37,7 @@
3737
}
3838
end
3939

40-
let(:resultset3) do
40+
let(:third_resultset) do
4141
{source_fixture("three.rb") => {"lines" => [nil, 1, 2]}}
4242
end
4343

@@ -49,61 +49,61 @@
4949
SimpleCov.enable_coverage :branch
5050
end
5151

52-
context "a merge" do
53-
subject do
54-
SimpleCov::Combine::ResultsCombiner.combine(resultset1, resultset2, resultset3)
52+
context "when a merge" do
53+
subject(:combined) do
54+
described_class.combine(first_resultset, second_resultset, third_resultset)
5555
end
5656

5757
it "has proper results for sample.rb" do
58-
expect(subject[source_fixture("sample.rb")]["lines"]).to eq([1, 1, 2, 2, nil, nil, 2, 2, nil, nil])
58+
expect(combined[source_fixture("sample.rb")]["lines"]).to eq([1, 1, 2, 2, nil, nil, 2, 2, nil, nil])
5959

6060
# gotta configure max line so it doesn't get ridiculous
6161
# rubocop:disable Style/IfUnlessModifier
6262
if SimpleCov.branch_coverage_supported?
63-
expect(subject[source_fixture("sample.rb")]["branches"][[:if, 3, 8, 6, 8, 36]][[:then, 4, 8, 6, 8, 12]]).to eq(47)
63+
expect(combined[source_fixture("sample.rb")]["branches"][[:if, 3, 8, 6, 8, 36]][[:then, 4, 8, 6, 8, 12]]).to eq(47)
6464
end
6565
# rubocop:enable Style/IfUnlessModifier
6666
end
6767

6868
it "has proper results for user.rb" do
69-
expect(subject[source_fixture("app/models/user.rb")]["lines"]).to eq([nil, 2, 6, 2, nil, nil, 2, 0, nil, nil])
69+
expect(combined[source_fixture("app/models/user.rb")]["lines"]).to eq([nil, 2, 6, 2, nil, nil, 2, 0, nil, nil])
7070

7171
if SimpleCov.branch_coverage_supported?
72-
expect(subject[source_fixture("app/models/user.rb")]["branches"][[:if, 3, 8, 6, 8, 36]][[:then, 4, 8, 6, 8, 12]]).to eq(48)
73-
expect(subject[source_fixture("app/models/user.rb")]["branches"][[:if, 3, 8, 6, 8, 36]][[:else, 5, 8, 6, 8, 36]]).to eq(26)
72+
expect(combined[source_fixture("app/models/user.rb")]["branches"][[:if, 3, 8, 6, 8, 36]][[:then, 4, 8, 6, 8, 12]]).to eq(48)
73+
expect(combined[source_fixture("app/models/user.rb")]["branches"][[:if, 3, 8, 6, 8, 36]][[:else, 5, 8, 6, 8, 36]]).to eq(26)
7474
end
7575
end
7676

7777
it "has proper results for sample_controller.rb" do
78-
expect(subject[source_fixture("app/controllers/sample_controller.rb")]["lines"]).to eq([nil, 4, 2, 1, nil, nil, 2, 0, nil, nil])
78+
expect(combined[source_fixture("app/controllers/sample_controller.rb")]["lines"]).to eq([nil, 4, 2, 1, nil, nil, 2, 0, nil, nil])
7979
end
8080

8181
it "has proper results for resultset1.rb" do
82-
expect(subject[source_fixture("resultset1.rb")]["lines"]).to eq([1, 1, 1, 1])
82+
expect(combined[source_fixture("resultset1.rb")]["lines"]).to eq([1, 1, 1, 1])
8383
end
8484

8585
it "has proper results for resultset2.rb" do
86-
expect(subject[source_fixture("resultset2.rb")]["lines"]).to eq([nil, 1, 1, nil])
86+
expect(combined[source_fixture("resultset2.rb")]["lines"]).to eq([nil, 1, 1, nil])
8787
end
8888

8989
it "has proper results for parallel_tests.rb" do
90-
expect(subject[source_fixture("parallel_tests.rb")]["lines"]).to eq([nil, nil, nil, 0])
90+
expect(combined[source_fixture("parallel_tests.rb")]["lines"]).to eq([nil, nil, nil, 0])
9191
end
9292

9393
it "has proper results for conditionally_loaded_1.rb" do
94-
expect(subject[source_fixture("conditionally_loaded_1.rb")]["lines"]).to eq([nil, 0, 1])
94+
expect(combined[source_fixture("conditionally_loaded_1.rb")]["lines"]).to eq([nil, 0, 1])
9595
end
9696

9797
it "has proper results for conditionally_loaded_2.rb" do
98-
expect(subject[source_fixture("conditionally_loaded_2.rb")]["lines"]).to eq([nil, 0, 1])
98+
expect(combined[source_fixture("conditionally_loaded_2.rb")]["lines"]).to eq([nil, 0, 1])
9999
end
100100

101101
it "has proper results for three.rb" do
102-
expect(subject[source_fixture("three.rb")]["lines"]).to eq([nil, 3, 7])
102+
expect(combined[source_fixture("three.rb")]["lines"]).to eq([nil, 3, 7])
103103
end
104104

105105
it "always returns a Hash object for branches", if: SimpleCov.branch_coverage_supported? do
106-
expect(subject[source_fixture("three.rb")]["branches"]).to eq({})
106+
expect(combined[source_fixture("three.rb")]["branches"]).to eq({})
107107
end
108108
end
109109
end
@@ -136,17 +136,17 @@
136136
end
137137

138138
it "merges frozen resultsets" do
139-
resultset1 = {
139+
first_resultset = {
140140
source_fixture("sample.rb").freeze => {"lines" => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil]},
141141
source_fixture("app/models/user.rb").freeze => {"lines" => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil]}
142142
}
143143

144-
resultset2 = {
144+
second_resultset = {
145145
source_fixture("sample.rb").freeze => {"lines" => [1, nil, 1, 1, nil, nil, 1, 1, nil, nil]}
146146
}
147147

148-
merged_result = SimpleCov::Combine::ResultsCombiner.combine(resultset1, resultset2)
149-
expect(merged_result.keys).to eq(resultset1.keys)
148+
merged_result = described_class.combine(first_resultset, second_resultset)
149+
expect(merged_result.keys).to eq(first_resultset.keys)
150150
expect(merged_result.values.map(&:frozen?)).to eq([false, false])
151151

152152
expect(merged_result[source_fixture("sample.rb")]["lines"]).to eq([1, 1, 2, 2, nil, nil, 2, 2, nil, nil])

spec/command_guesser_spec.rb

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,58 +3,58 @@
33
require "helper"
44

55
describe SimpleCov::CommandGuesser do
6-
subject { SimpleCov::CommandGuesser }
6+
subject(:guesser) { described_class }
77

88
it 'correctly guesses "Unit Tests" for unit tests' do
9-
subject.original_run_command = "/some/path/test/units/foo_bar_test.rb"
10-
expect(subject.guess).to eq("Unit Tests")
11-
subject.original_run_command = "test/units/foo.rb"
12-
expect(subject.guess).to eq("Unit Tests")
13-
subject.original_run_command = "test/foo.rb"
14-
expect(subject.guess).to eq("Unit Tests")
15-
subject.original_run_command = "test/{models,helpers,unit}/**/*_test.rb"
16-
expect(subject.guess).to eq("Unit Tests")
9+
guesser.original_run_command = "/some/path/test/units/foo_bar_test.rb"
10+
expect(guesser.guess).to eq("Unit Tests")
11+
guesser.original_run_command = "test/units/foo.rb"
12+
expect(guesser.guess).to eq("Unit Tests")
13+
guesser.original_run_command = "test/foo.rb"
14+
expect(guesser.guess).to eq("Unit Tests")
15+
guesser.original_run_command = "test/{models,helpers,unit}/**/*_test.rb"
16+
expect(guesser.guess).to eq("Unit Tests")
1717
end
1818

1919
it 'correctly guesses "Functional Tests" for functional tests' do
20-
subject.original_run_command = "/some/path/test/functional/foo_bar_controller_test.rb"
21-
expect(subject.guess).to eq("Functional Tests")
22-
subject.original_run_command = "test/{controllers,mailers,functional}/**/*_test.rb"
23-
expect(subject.guess).to eq("Functional Tests")
20+
guesser.original_run_command = "/some/path/test/functional/foo_bar_controller_test.rb"
21+
expect(guesser.guess).to eq("Functional Tests")
22+
guesser.original_run_command = "test/{controllers,mailers,functional}/**/*_test.rb"
23+
expect(guesser.guess).to eq("Functional Tests")
2424
end
2525

2626
it 'correctly guesses "Integration Tests" for integration tests' do
27-
subject.original_run_command = "/some/path/test/integration/foo_bar_controller_test.rb"
28-
expect(subject.guess).to eq("Integration Tests")
29-
subject.original_run_command = "test/integration/**/*_test.rb"
30-
expect(subject.guess).to eq("Integration Tests")
27+
guesser.original_run_command = "/some/path/test/integration/foo_bar_controller_test.rb"
28+
expect(guesser.guess).to eq("Integration Tests")
29+
guesser.original_run_command = "test/integration/**/*_test.rb"
30+
expect(guesser.guess).to eq("Integration Tests")
3131
end
3232

3333
it 'correctly guesses "Cucumber Features" for cucumber features' do
34-
subject.original_run_command = "features"
35-
expect(subject.guess).to eq("Cucumber Features")
36-
subject.original_run_command = "cucumber"
37-
expect(subject.guess).to eq("Cucumber Features")
34+
guesser.original_run_command = "features"
35+
expect(guesser.guess).to eq("Cucumber Features")
36+
guesser.original_run_command = "cucumber"
37+
expect(guesser.guess).to eq("Cucumber Features")
3838
end
3939

4040
it 'correctly guesses "RSpec" for RSpec' do
41-
subject.original_run_command = "/some/path/spec/foo.rb"
42-
expect(subject.guess).to eq("RSpec")
41+
guesser.original_run_command = "/some/path/spec/foo.rb"
42+
expect(guesser.guess).to eq("RSpec")
4343
end
4444

4545
it "defaults to RSpec because RSpec constant is defined" do
46-
subject.original_run_command = "some_arbitrary_command with arguments"
47-
expect(subject.guess).to eq("RSpec")
46+
guesser.original_run_command = "some_arbitrary_command with arguments"
47+
expect(guesser.guess).to eq("RSpec")
4848
end
4949

5050
it "appends parallel data" do
51-
subject.original_run_command = "/some/path/spec/foo.rb"
51+
guesser.original_run_command = "/some/path/spec/foo.rb"
5252
allow(ENV).to receive(:[]).and_call_original
5353
allow(ENV).to receive(:fetch).and_call_original
5454
allow(ENV).to receive(:[]).with("TEST_ENV_NUMBER").and_return("1")
5555
allow(ENV).to receive(:[]).with("PARALLEL_TEST_GROUPS").and_return("2")
5656
allow(ENV).to receive(:fetch).with("TEST_ENV_NUMBER", nil).and_return("1")
5757
allow(ENV).to receive(:fetch).with("PARALLEL_TEST_GROUPS", nil).and_return("2")
58-
expect(subject.guess).to eq("RSpec (1/2)")
58+
expect(guesser.guess).to eq("RSpec (1/2)")
5959
end
6060
end

spec/config_loader_spec.rb

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

33
require "helper"
44

5-
describe "loading config" do
5+
describe "loading config" do # rubocop:disable RSpec/DescribeClass
66
context "without ENV[HOME]" do
77
it "does not raise any errors" do
88
home = ENV.delete("HOME")

spec/configuration_spec.rb

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@
4242

4343
it "still returns the configured token (after the deprecation warning)" do
4444
capture_stderr { config.nocov_token("skippit") }
45-
stderr = capture_stderr { @value = config.nocov_token }
45+
value = nil
46+
stderr = capture_stderr { value = config.nocov_token }
4647

47-
expect(@value).to eq "skippit"
48+
expect(value).to eq "skippit"
4849
expect(stderr).to include("[DEPRECATION]") # the read still warns
4950
end
5051

@@ -58,9 +59,10 @@
5859

5960
describe "#current_nocov_token" do
6061
it "returns the configured token without emitting a deprecation warning" do
61-
stderr = capture_stderr { @value = config.current_nocov_token }
62+
value = nil
63+
stderr = capture_stderr { value = config.current_nocov_token }
6264

63-
expect(@value).to eq "nocov"
65+
expect(value).to eq "nocov"
6466
expect(stderr).to be_empty
6567
end
6668

@@ -81,7 +83,7 @@
8183
expect(config.tracked_files).to eq glob
8284
end
8385

84-
context "and configured again with nil" do
86+
context "when configured again with nil" do
8587
before { config.track_files(nil) }
8688

8789
it "returns nil" do
@@ -102,13 +104,15 @@
102104
end
103105

104106
it "does not warn you about your usage" do
105-
expect(config).not_to receive(:warn)
107+
allow(config).to receive(:warn)
106108
config.public_send(coverage_setting, 100.00)
109+
expect(config).not_to have_received(:warn)
107110
end
108111

109112
it "warns you about your usage" do
110-
expect(config).to receive(:warn).with("The coverage you set for #{coverage_setting} is greater than 100%")
113+
allow(config).to receive(:warn)
111114
config.public_send(coverage_setting, 100.01)
115+
expect(config).to have_received(:warn).with("The coverage you set for #{coverage_setting} is greater than 100%")
112116
end
113117

114118
it "sets the right coverage value when called with a number" do
@@ -177,13 +181,15 @@
177181
end
178182

179183
it "does not warn you about your usage" do
180-
expect(config).not_to receive(:warn)
184+
allow(config).to receive(:warn)
181185
config.minimum_coverage_by_group({"Test Group 1" => 100.00})
186+
expect(config).not_to have_received(:warn)
182187
end
183188

184189
it "warns you about your usage" do
185-
expect(config).to receive(:warn).with("The coverage you set for minimum_coverage_by_group is greater than 100%")
190+
allow(config).to receive(:warn)
186191
config.minimum_coverage_by_group({"Test Group 1" => 100.01})
192+
expect(config).to have_received(:warn).with("The coverage you set for minimum_coverage_by_group is greater than 100%")
187193
end
188194

189195
it "sets the right coverage value when called with a number" do
@@ -377,20 +383,20 @@
377383

378384
describe "#enable_for_subprocesses" do
379385
it "returns false by default" do
380-
expect(config.enable_for_subprocesses).to eq false
386+
expect(config.enable_for_subprocesses).to be false
381387
end
382388

383389
it "can be set to true" do
384390
config.enable_for_subprocesses true
385391

386-
expect(config.enable_for_subprocesses).to eq true
392+
expect(config.enable_for_subprocesses).to be true
387393
end
388394

389395
it "can be enabled and then disabled again" do
390396
config.enable_for_subprocesses true
391397
config.enable_for_subprocesses false
392398

393-
expect(config.enable_for_subprocesses).to eq false
399+
expect(config.enable_for_subprocesses).to be false
394400
end
395401
end
396402

0 commit comments

Comments
 (0)