Module: SimpleCov
- Defined in:
- lib/simplecov/profiles.rb,
lib/simplecov.rb,
lib/simplecov/filter.rb,
lib/simplecov/result.rb,
lib/simplecov/railtie.rb,
lib/simplecov/version.rb,
lib/simplecov/last_run.rb,
lib/simplecov/file_list.rb,
lib/simplecov/formatter.rb,
lib/simplecov/exit_codes.rb,
lib/simplecov/source_file.rb,
lib/simplecov/raw_coverage.rb,
lib/simplecov/configuration.rb,
lib/simplecov/result_merger.rb,
lib/simplecov/command_guesser.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: CommandGuesser, Configuration, ExitCodes, Formatter, LastRun, RawCoverage, ResultMerger Classes: ArrayFilter, BlockFilter, FileList, Filter, Profiles, Railtie, Result, SourceFile, StringFilter
Constant Summary collapse
- VERSION =
version
Class Attribute Summary collapse
-
.pid ⇒ Object
Returns the value of attribute pid.
-
.running ⇒ Object
Returns the value of attribute running.
Class Method Summary collapse
-
.add_not_loaded_files(result) ⇒ Object
Finds files that were to be tracked but were not loaded and initializes their coverage to zero.
-
.clear_result! ⇒ Object
Clear out the previously cached .result.
-
.filtered(files) ⇒ Object
Applies the configured filters to the given array of SimpleCov::SourceFile items.
-
.grouped(files) ⇒ Object
Applies the configured groups to the given array of SimpleCov::SourceFile items.
- .load_adapter(name) ⇒ Object
-
.load_profile(name) ⇒ Object
Applies the profile of given name on SimpleCov configuration.
-
.result ⇒ Object
Returns the result for the current coverage run, merging it across test suites from cache using SimpleCov::ResultMerger if use_merging is activated (default).
-
.result? ⇒ Boolean
Returns nil if the result has not been computed Otherwise, returns the result.
-
.start(profile = nil, &block) ⇒ Object
Sets up SimpleCov to run against your project.
-
.usable? ⇒ Boolean
Checks whether we’re on a proper version of Ruby (likely 1.9+) which provides coverage support.
Class Attribute Details
.pid ⇒ Object
Returns the value of attribute pid.
22 23 24 |
# File 'lib/simplecov.rb', line 22 def pid @pid end |
.running ⇒ Object
Returns the value of attribute running.
21 22 23 |
# File 'lib/simplecov.rb', line 21 def running @running end |
Class Method Details
.add_not_loaded_files(result) ⇒ Object
Finds files that were to be tracked but were not loaded and initializes their coverage to zero.
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/simplecov.rb', line 60 def add_not_loaded_files(result) if tracked_files result = result.dup Dir[tracked_files].each do |file| absolute = File.(file) result[absolute] ||= [0] * File.foreach(absolute).count end end result end |
.clear_result! ⇒ Object
Clear out the previously cached .result. Primarily useful in testing
163 164 165 |
# File 'lib/simplecov.rb', line 163 def clear_result! @result = nil end |
.filtered(files) ⇒ Object
Applies the configured filters to the given array of SimpleCov::SourceFile items
108 109 110 111 112 113 114 |
# File 'lib/simplecov.rb', line 108 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
119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/simplecov.rb', line 119 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.empty? && !(other_files = files.reject { |source_file| grouped_files.include?(source_file) }).empty? grouped["Ungrouped"] = SimpleCov::FileList.new(other_files) end grouped end |
.load_adapter(name) ⇒ Object
139 140 141 142 |
# File 'lib/simplecov.rb', line 139 def load_adapter(name) warn "#{Kernel.caller.first}: [DEPRECATION] #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
135 136 137 |
# File 'lib/simplecov.rb', line 135 def load_profile(name) profiles.load(name) end |
.result ⇒ Object
Returns the result for the current coverage run, merging it across test suites from cache using SimpleCov::ResultMerger if use_merging is activated (default)
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/simplecov.rb', line 77 def result return @result if result? # Collect our coverage result if running @result = SimpleCov::Result.new add_not_loaded_files(Coverage.result) end # If we're using merging of results, store the current result # first (if there is one), then merge the results and return those if use_merging SimpleCov::ResultMerger.store_result(@result) if result? @result = SimpleCov::ResultMerger.merged_result end @result ensure self.running = false end |
.result? ⇒ Boolean
Returns nil if the result has not been computed Otherwise, returns the result
101 102 103 |
# File 'lib/simplecov.rb', line 101 def result? defined?(@result) && @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
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/simplecov.rb', line 41 def start(profile = nil, &block) if SimpleCov.usable? load_profile(profile) if profile configure(&block) if block_given? @result = nil self.running = true self.pid = Process.pid 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
148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/simplecov.rb', line 148 def usable? return @usable if defined?(@usable) && !@usable.nil? @usable = begin require "coverage" require "simplecov/jruby_fix" true rescue LoadError false end end |