Module: SimpleCov::CommandGuesser
| Relationships & Source Files | |
| Defined in: | lib/simplecov/command_guesser.rb |
Overview
Helper that tries to find out what test suite is running (for SimpleCov.command_name)
Constant Summary
-
COMMAND_LINE_FRAMEWORKS =
private
# File 'lib/simplecov/command_guesser.rb', line 31{ %r{test/functional/} => "Functional Tests", %r{test/\{.*functional.*\}/} => "Functional Tests", %r{test/integration/} => "Integration Tests", %r{test/} => "Unit Tests", /spec/ => "RSpec", /cucumber/ => "Cucumber Features", /features/ => "Cucumber Features" }.freeze -
DEFINED_CONSTANT_FRAMEWORKS =
private
# File 'lib/simplecov/command_guesser.rb', line 49
Inner array literals after the first are flagged uncovered by Ruby's Coverage module even though the constant evaluates as a whole — known quirk with multi-line array literals.
[ ["RSpec", -> { defined?(::RSpec) }], ["Unit Tests", -> { defined?(Test::Unit) }], # simplecov:disable ["Minitest", -> { defined?(::Minitest) }], # simplecov:disable ["MiniTest", -> { defined?(MiniTest) }] # simplecov:disable ].freeze
Class Attribute Summary
-
.original_run_command
rw
Storage for the original command line call that invoked the test suite.
Class Method Summary
- .guess
- .from_command_line_options private
-
.from_defined_constants
private
If the command regexps fail, let's try checking defined constants.
- .parallel_data private
Class Attribute Details
.original_run_command (rw)
Storage for the original command line call that invoked the test suite. This has got to be stored as early as possible because i.e. rake and test/unit 2 have a habit of tampering with ARGV, which makes i.e. the automatic distinction between rails unit/functional/integration tests impossible without this cached item.
# File 'lib/simplecov/command_guesser.rb', line 14
attr_accessor :original_run_command
Class Method Details
.from_command_line_options (private)
[ GitHub ]# File 'lib/simplecov/command_guesser.rb', line 42
def COMMAND_LINE_FRAMEWORKS.find { |pattern, _| pattern.match?(original_run_command.to_s) }&.last end
.from_defined_constants (private)
If the command regexps fail, let's try checking defined constants.
# File 'lib/simplecov/command_guesser.rb', line 58
def from_defined_constants # simplecov:disable branch — first iter returns when ::RSpec is defined; later branches unreachable DEFINED_CONSTANT_FRAMEWORKS.each { |name, defined_check| return name if defined_check.call } # simplecov:enable branch # TODO: Provide link to docs/wiki article # simplecov:disable — only fires when no framework is detected, which # is impossible while our own specs are running under rspec warn( "SimpleCov failed to recognize the test framework and/or suite used. " \ "Please specify manually using SimpleCov.command_name 'Unit Tests'." ) "Unknown Test Framework" # simplecov:enable end
.guess
[ GitHub ]# File 'lib/simplecov/command_guesser.rb', line 16
def guess [ || from_defined_constants, parallel_data].compact.join(" ") end
.parallel_data (private)
[ GitHub ]# File 'lib/simplecov/command_guesser.rb', line 22
def parallel_data # If being run from inside parallel_tests set the command name according to the process number return unless ENV["PARALLEL_TEST_GROUPS"] && ENV["TEST_ENV_NUMBER"] number = ENV.fetch("TEST_ENV_NUMBER", nil) number = "1" if number.empty? "(#{number}/#{ENV.fetch('PARALLEL_TEST_GROUPS', nil)})" end