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

Prevent an "instance variable not initialized" warning #938

Merged
merged 3 commits into from
Oct 25, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions features/warnings.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@rspec
Feature:

Running SimpleCov with verbosity enabled does not yield warnings.

Background:
Given I'm working on the project "faked_project"

Scenario:
Given SimpleCov for RSpec is configured with:
"""
require 'simplecov'
SimpleCov.start
"""

When I successfully run `bundle exec rspec --warnings spec`
Then a coverage report should have been generated
And the output should not contain "warning"
5 changes: 3 additions & 2 deletions lib/simplecov/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,9 @@ def at_exit(&block)
# gets or sets the enabled_for_subprocess configuration
# when true, this will inject SimpleCov code into Process.fork
def enable_for_subprocesses(value = nil)
@enable_for_subprocesses = value unless value.nil?
@enable_for_subprocesses || false
return @enable_for_subprocesses if defined?(@enable_for_subprocesses) && value.nil?

@enable_for_subprocesses = value || false
end

# gets the enabled_for_subprocess configuration
Expand Down
19 changes: 19 additions & 0 deletions spec/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,24 @@
expect(config).not_to be_branch_coverage
end
end

describe "#enable_for_subprocesses" do
it "returns false by default" do
expect(config.enable_for_subprocesses).to eq false
end

it "can be set to true" do
config.enable_for_subprocesses true

expect(config.enable_for_subprocesses).to eq true
end

it "can be enabled and then disabled again" do
config.enable_for_subprocesses true
config.enable_for_subprocesses false

expect(config.enable_for_subprocesses).to eq false
end
end
end
end