lib/simplecov.rb in simplecov-0.7.1 vs lib/simplecov.rb in simplecov-0.8.0.pre

- old
+ new

@@ -1,21 +1,18 @@ # # Code coverage for ruby 1.9. Please check out README for a full introduction. # module SimpleCov - # Indicates invalid coverage data - class CoverageDataError < StandardError; end; - class << self - attr_accessor :running#, :result # TODO: Remove result? + attr_accessor :running # # Sets up SimpleCov to run against your project. - # You can optionally specify an adapter to use as well as configuration with a block: + # You can optionally specify a profile to use as well as configuration with a block: # SimpleCov.start # OR - # SimpleCov.start 'rails' # using rails adapter + # SimpleCov.start 'rails' # using rails profile # OR # SimpleCov.start do # add_filter 'test' # end # OR @@ -23,19 +20,21 @@ # add_filter 'test' # end # # Please check out the RDoc for SimpleCov::Configuration to find about available config options # - def start(adapter=nil, &block) - return false unless SimpleCov.usable? - - require 'coverage' - load_adapter(adapter) unless adapter.nil? - Coverage.start - configure(&block) if block_given? - @result = nil - self.running = true + def start(profile=nil, &block) + if SimpleCov.usable? + load_profile(profile) if profile + configure(&block) if block_given? + @result = nil + self.running = true + Coverage.start + else + warn "WARNING: SimpleCov is activated, but you're not running Ruby 1.9+ - no coverage analysis will happen" + false + end end # # Returns the result for the current coverage run, merging it across test suites # from cache using SimpleCov::ResultMerger if use_merging is activated (default) @@ -88,36 +87,45 @@ end grouped end # - # Applies the adapter of given name on SimpleCov configuration + # Applies the profile of given name on SimpleCov configuration # + def load_profile(name) + profiles.load(name) + end + def load_adapter(name) - adapters.load(name) + warn "method load_adapter is deprecated. use load_profile instead" + load_profile(name) end # - # Checks whether we're on a proper version of ruby (1.9+) and returns false if this is not the case, - # also printing an appropriate warning + # Checks whether we're on a proper version of Ruby (likely 1.9+) which + # provides coverage support # def usable? - unless "1.9".respond_to?(:encoding) - warn "WARNING: SimpleCov is activated, but you're not running Ruby 1.9+ - no coverage analysis will happen" - return false + return @usable if defined? @usable and !@usable.nil? + + @usable = begin + require 'coverage' + require 'simplecov/jruby16_fix' + true + rescue LoadError + false end - true end end end $LOAD_PATH.unshift(File.join(File.dirname(__FILE__))) require 'simplecov/configuration' SimpleCov.send :extend, SimpleCov::Configuration require 'simplecov/exit_codes' require 'simplecov/json' -require 'simplecov/adapters' +require 'simplecov/profiles' require 'simplecov/source_file' require 'simplecov/file_list' require 'simplecov/result' require 'simplecov/filter' require 'simplecov/formatter' @@ -126,9 +134,9 @@ require 'simplecov/result_merger' require 'simplecov/command_guesser' require 'simplecov/version' # Load default config -require 'simplecov/defaults' +require 'simplecov/defaults' unless ENV['SIMPLECOV_NO_DEFAULTS'] # Load Rails integration (only for Rails 3, see #113) require 'simplecov/railtie' if defined? Rails::Railtie