Module: SimpleCov

Defined in:
lib/simplecov.rb,
lib/simplecov/filter.rb,
lib/simplecov/result.rb,
lib/simplecov/version.rb,
lib/simplecov/railtie.rb,
lib/simplecov/formatter.rb,
lib/simplecov/source_file.rb,
lib/simplecov/formatter/multi_formatter.rb,
lib/simplecov/formatter/simple_formatter.rb

Overview

A ridiculously simple formatter for SimpleCov results.

Defined Under Namespace

Modules: ArrayMergeHelper, CommandGuesser, Configuration, ExitCodes, Formatter, HashMergeHelper, JSON, LastRun, ResultMerger Classes: BlockFilter, FileList, Filter, Profiles, Railtie, Result, SourceFile, StringFilter

Constant Summary collapse

VERSION =
"0.9.1"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.runningObject

Returns the value of attribute running


6
7
8
# File 'lib/simplecov.rb', line 6

def running
  @running
end

Class Method Details

.filtered(files) ⇒ Object

Applies the configured filters to the given array of SimpleCov::SourceFile items


68
69
70
71
72
73
74
# File 'lib/simplecov.rb', line 68

def filtered(files)
  result = files.clone
  filters.each do |filter|
    result = result.reject {|source_file| filter.matches?(source_file) }
  end
  SimpleCov::FileList.new result
end

.grouped(files) ⇒ Object

Applies the configured groups to the given array of SimpleCov::SourceFile items


79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/simplecov.rb', line 79

def grouped(files)
  grouped = {}
  grouped_files = []
  groups.each do |name, filter|
    grouped[name] = SimpleCov::FileList.new(files.select {|source_file| filter.matches?(source_file)})
    grouped_files += grouped[name]
  end
  if groups.length > 0 and (other_files = files.reject {|source_file| grouped_files.include?(source_file)}).length > 0
    grouped["Ungrouped"] = SimpleCov::FileList.new(other_files)
  end
  grouped
end

.load_adapter(name) ⇒ Object


99
100
101
102
# File 'lib/simplecov.rb', line 99

def load_adapter(name)
  warn "method load_adapter is deprecated. use load_profile instead"
  load_profile(name)
end

.load_profile(name) ⇒ Object

Applies the profile of given name on SimpleCov configuration


95
96
97
# File 'lib/simplecov.rb', line 95

def load_profile(name)
  profiles.load(name)
end

.resultObject

Returns the result for the current coverage run, merging it across test suites from cache using SimpleCov::ResultMerger if use_merging is activated (default)


43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/simplecov.rb', line 43

def result
  @result ||= SimpleCov::Result.new(Coverage.result) if running
  # If we're using merging of results, store the current result
  # first, then merge the results and return those
  if use_merging
    SimpleCov::ResultMerger.store_result(@result) if @result
    return SimpleCov::ResultMerger.merged_result
  else
    return @result if defined? @result
  end
ensure
  self.running = false
end

.result?Boolean

Returns nil if the result has not been computed Otherwise, returns the result

Returns:

  • (Boolean)

61
62
63
# File 'lib/simplecov.rb', line 61

def result?
  defined? @result and @result
end

.start(profile = nil, &block) ⇒ Object

Sets up SimpleCov to run against your project. You can optionally specify a profile to use as well as configuration with a block:

SimpleCov.start
 OR
SimpleCov.start 'rails' # using rails profile
 OR
SimpleCov.start do
  add_filter 'test'
end
  OR
SimpleCov.start 'rails' do
  add_filter 'test'
end

Please check out the RDoc for SimpleCov::Configuration to find about available config options


25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/simplecov.rb', line 25

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"
    warn "Starting with SimpleCov 1.0.0, even no-op compatibility with Ruby <= 1.8 will be entirely dropped."
    false
  end
end

.usable?Boolean

Checks whether we're on a proper version of Ruby (likely 1.9+) which provides coverage support

Returns:

  • (Boolean)

108
109
110
111
112
113
114
115
116
117
118
# File 'lib/simplecov.rb', line 108

def usable?
  return @usable if defined? @usable and !@usable.nil?

  @usable = begin
    require 'coverage'
    require 'simplecov/jruby_fix'
    true
  rescue LoadError
    false
  end
end