Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 56 lines (46 sloc) 1.281 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
require 'rspec/core/formatters/base_formatter'
require 'simplecov'

# This formatter does nothing else but run SimpleCov. That means that if you run this formatter on
# its own, you won't get any output. It is advised to add your favorite formatter, like this, to see
# test failures and so on:
#
# rspec spec -f SpecCoverage -fd
#
class SpecCoverage < ::RSpec::Core::Formatters::BaseFormatter

  def initialize(*)
    super
    add_default_filter
    load_simplecov_config
    start_simplecov
  end

  private

  # This is an RSpec filter, so we can safely assume that specs should be ignored
  def add_default_filter
    SimpleCov.add_filter '/spec/'
  end

  # Load a local .coverage file, to customize it yourself
  #
  # Example contents of this file:
  #
  # SimpleCov.start do
  # add_filter '/foo/'
  # end
  #
  # Rails users might want to add at least something like:
  #
  # SimpleCov.start 'rails'
  #
  def load_simplecov_config
    load config_file if config_exists?
  end

  def config_exists?
    File.exist?(config_file)
  end

  def config_file
    File.expand_path(".coverage", SimpleCov.root)
  end

  # If you didn't start SimpleCov in your .coverage file, start it now
  def start_simplecov
    SimpleCov.start unless SimpleCov.running
  end

end
Something went wrong with that request. Please try again.