Skip to content

Commit

Permalink
More documentation; Removed unneccessary attr_accessor
Browse files Browse the repository at this point in the history
  • Loading branch information
colszowka committed Aug 23, 2010
1 parent 88d632b commit bbb1c22
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 15 deletions.
19 changes: 19 additions & 0 deletions README.rdoc
Expand Up @@ -213,6 +213,25 @@ adapter and customize it so you can reuse it in unit tests and cucumber features
# test/test_helper.rb
require 'simplecov_custom_adapter'
SimpleCov.start 'myadapter'

== Customizing exit behaviour

You can define what simplecov should do when your test suite finishes by customizing the at_exit hook:

SimpleCov.at_exit do
SimpleCov.result.format!
end

Above is the default behaviour. Do whatever you like instead!

== Using your own formatter

You can use your own formatter with:

SimpleCov.formatter = SimpleCov::Formatter::HTMLFormatter

When calling SimpleCov.result.format!, it will be invoked with SimpleCov::Formatter::YourFormatter.new.format(result), "result"
being an instance of SimpleCov::Result. Do whatever your wish with that!

== Configuration options

Expand Down
35 changes: 23 additions & 12 deletions lib/simplecov.rb
@@ -1,14 +1,32 @@
#
# Code coverage for ruby 1.9. Please check out README for a full introduction.
#
module SimpleCov
# Indicates invalid coverage data
class CoverageDataError < StandardError; end;

# The version of the simplecov gem
VERSION = File.read(File.join(File.dirname(__FILE__), '../VERSION'))

class << self
attr_accessor :running, :result # TODO: Remove result?
attr_accessor :running#, :result # TODO: Remove result?

#
# Sets up SimpleCov to run against your project.
# You can optionally specify an adapter to use as well as configuration with a block:
# SimpleCov.start
# OR
# SimpleCov.start 'rails' # using rails adapter
# OR
# SimpleCov.start do
# add_filter 'test'
# end
# OR
# SimpleCov.start 'rails' do
# add_filter 'test'
# end
#
# TODO: Explain config! Add default adapters!
# Please check out the RDoc for SimpleCov::Configuration to find about available config options
#
def start(adapter=nil, &block)
unless "1.9".respond_to?(:encoding)
Expand All @@ -24,12 +42,13 @@ def start(adapter=nil, &block)
end

#
# Returns the result for the currntly runnig coverage run
# Returns the result for the current coverage run, merging it across test suites
# from cache using SimpleCov::ResultMerger if use_merging is activated (default)
#
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 them
# first, then merge the results and return those
if use_merging
SimpleCov::ResultMerger.store_result(@result) if @result
return SimpleCov::ResultMerger.merged_result
Expand All @@ -40,14 +59,6 @@ def result
self.running = false
end

#
# Returns the project name - currently assuming the last dirname in
# the SimpleCov.root is this
#
def project_name
File.basename(root.split('/').last).capitalize.gsub('_', ' ')
end

#
# Applies the configured filters to the given array of SimpleCov::SourceFile items
#
Expand Down
22 changes: 19 additions & 3 deletions lib/simplecov/configuration.rb
Expand Up @@ -79,14 +79,15 @@ def adapters
end

#
# Configure SimpleCov using a block:
# Allows you to configure simplecov in a block instead of prepending SimpleCov to all config methods
# you're calling.
#
# SimpleCov.configure do
# add_filter 'foobar'
# end
#
# This is equivalent to SimpleCov.add_filter 'foobar' and thus makes it easier to set a lot of configure
# options.
# This is equivalent to SimpleCov.add_filter 'foobar' and thus makes it easier to set a buchn of configure
# options at once.
#
def configure(&block)
instance_exec(&block)
Expand All @@ -109,6 +110,16 @@ def at_exit(&block)
@at_exit ||= Proc.new { SimpleCov.result.format! }
end

#
# Returns the project name - currently assuming the last dirname in
# the SimpleCov.root is this.
#
def project_name(new_name=nil)
return @project_name if @project_name and new_name.nil?
@project_name = new_name if new_name.kind_of?(String)
@project_name ||= File.basename(root.split('/').last).capitalize.gsub('_', ' ')
end

#
# Defines whether to use result merging so all your test suites (test:units, test:functionals, cucumber, ...)
# are joined and combined into a single coverage report
Expand Down Expand Up @@ -153,6 +164,11 @@ def add_filter(filter_argument=nil, &filter_proc)
filters << parse_filter(filter_argument, &filter_proc)
end

#
# Define a group for files. Works similar to add_filter, only that the first
# argument is the desired group name and files PASSING the filter end up in the group
# (while filters exclude when the filter is applicable).
#
def add_group(group_name, filter_argument=nil, &filter_proc)
groups[group_name] = parse_filter(filter_argument, &filter_proc)
end
Expand Down

0 comments on commit bbb1c22

Please sign in to comment.