Sha256: 53e2bb207474c61103580bc0b5ef38a8f43d0a33eb8ad36e6eef1ba771c791b3

Contents?: true

Size: 1.83 KB

Versions: 1

Compression:

Stored size: 1.83 KB

Contents

#
# Helper that tries to find out what test suite is running (for SimpleCov.command_name)
#
module SimpleCov::CommandGuesser
  class << self
    # 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.
    attr_accessor :original_run_command
    
    def guess
      from_env || from_command_line_options || from_defined_constants
    end
    
    private

    def from_env
      # If being run from inside parallel_tests set the command name according to the process number
      if ENV['PARALLEL_TEST_GROUPS'] && ENV['TEST_ENV_NUMBER']
        number = ENV['TEST_ENV_NUMBER']
        number = '1' if number == ''
        "(#{number}/#{ENV['PARALLEL_TEST_GROUPS']})"
      end
    end
    
    def from_command_line_options
      case original_run_command
        when /test\/functional\//, /test\/{.*?functional.*?}\//
          "Functional Tests"
        when /test\/integration\//
          "Integration Tests"
        when /test\//
          "Unit Tests"
        when /spec/
          "RSpec"
        when /cucumber/, /features/
          "Cucumber Features"
        else
          nil
      end
    end
  
    def from_defined_constants
      # If the command regexps fail, let's try checking defined constants.
      if defined?(RSpec)
        "RSpec"
      elsif defined?(Test::Unit)
        "Unit Tests"
      else
        # TODO: Provide link to docs/wiki article
        warn "SimpleCov failed to recognize the test framework and/or suite used. Please specify manually using SimpleCov.command_name 'Unit Tests'."
        'Unknown Test Framework'
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
simplecov-0.8.0.pre2 lib/simplecov/command_guesser.rb