Skip to content
Browse files

Initial commit

  • Loading branch information...
0 parents commit 976adbddd48d9ac0e6092959ded7edf7cbbd3b2f @iain committed
Showing with 133 additions and 0 deletions.
  1. +17 −0 .gitignore
  2. +4 −0 Gemfile
  3. +28 −0 README.md
  4. +2 −0 Rakefile
  5. +57 −0 lib/spec_coverage.rb
  6. +3 −0 lib/spec_coverage/version.rb
  7. +22 −0 spec_coverage.gemspec
17 .gitignore
@@ -0,0 +1,17 @@
+*.gem
+*.rbc
+.bundle
+.config
+.yardoc
+Gemfile.lock
+InstalledFiles
+_yardoc
+coverage
+doc/
+lib/bundler/man
+pkg
+rdoc
+spec/reports
+test/tmp
+test/version_tmp
+tmp
4 Gemfile
@@ -0,0 +1,4 @@
+source 'http://rubygems.org'
+
+# Specify your gem's dependencies in spec_coverage.gemspec
+gemspec
28 README.md
@@ -0,0 +1,28 @@
+# SpecCoverage
+
+This formatter loads SimpleCov a code coverage reporting tool for Ruby 1.9. SimpleCov already does a good job in making it really easy to configure and load itself, but even good efforts can be improved upon.
+
+The only problem is that you'll need to have something like a spec_helper to load it. You might not have this or you might find it ugly having to resort to environment variables to turn it off or on.
+
+## Installation
+
+If you are using bundler, then don't forget to add simplecov to your `Gemfile`:
+
+ gem 'simplecov', :group => :test, :require => false
+
+
+## Usage
+
+With this formatter, SimpleCov will start, and it will load a `.coverage` file in which you can add ruby code to configure SimpleCov in a non-obtrusive way. Configuration for a typical Rails app will look like this:
+
+ SimpleCov.start 'rails'
+
+This formatter doesn't have any output, so you'll probably want to add another formatter. I prefer the documentation (if the number of specs is limited) or Fuubar formatter (for big spec suites):
+
+ rspec spec -f SpecCoverage -fd
+ rspec spec -f SpecCoverage -f Fuubar
+
+
+More information on SimpleCov can be found [here](https://github.com/colszowka/simplecov).
+
+More information on RSpec formatters can be found [here](http://relishapp.com/rspec/rspec-core/v/2-6/dir/command-line/format-option).
2 Rakefile
@@ -0,0 +1,2 @@
+#!/usr/bin/env rake
+require 'bundler/gem_tasks'
57 lib/spec_coverage.rb
@@ -0,0 +1,57 @@
+require "spec_coverage/version"
+
+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
3 lib/spec_coverage/version.rb
@@ -0,0 +1,3 @@
+module SpecCoverage
+ VERSION = "0.0.1"
+end
22 spec_coverage.gemspec
@@ -0,0 +1,22 @@
+# -*- encoding: utf-8 -*-
+require File.expand_path('../lib/spec_coverage/version', __FILE__)
+
+Gem::Specification.new do |gem|
+ gem.authors = ["Iain Hecker"]
+ gem.email = ["iain@iain.nl"]
+ gem.description = %q{Use SimpleCov more easily as an RSpec formatter}
+ gem.summary = %q{SpecCoverage allows you to use SimpleCov whenever you want, without having to put it in your spec_helper.rb file. It doesn’t output anything like you’d expect from a normal formatter, so you’re going to have to use another one to see your test output.}
+ gem.homepage = 'https://github.com/iain/spec_coverage'
+
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ gem.files = `git ls-files`.split("\n")
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ gem.name = "spec_coverage"
+ gem.require_paths = ['lib']
+ gem.version = SpecCoverage::VERSION
+
+ gem.add_dependency('rspec', ['~> 2.0'])
+ gem.add_dependency('simplecov', ['~> 0.4.2'])
+
+ gem.required_ruby_version = ">= 1.9"
+end

0 comments on commit 976adbd

Please sign in to comment.
Something went wrong with that request. Please try again.