Permalink
Browse files

Initial Commit

  • Loading branch information...
0 parents commit cc011aa898b16673584c82bbe4804e76a6aafbf2 @markbates committed Aug 13, 2010
@@ -0,0 +1,2 @@
+---
+BUNDLE_DISABLE_SHARED_GEMS: "1"
@@ -0,0 +1,22 @@
+.swp
+*.swp
+*.log
+.DS_Store
+doc
+tmp
+pkg
+*.gem
+*.pid
+coverage
+coverage.data
+build/*
+*.pbxuser
+*.mode1v3
+.svn
+profile
+sqlnet.log
+db/schema.rb
+dump.*.gz
+solr/*
+log/*
+public/system/*
1 .rvmrc
@@ -0,0 +1 @@
+rvm use ruby-1.9.2-rc2@cover_me
@@ -0,0 +1,7 @@
+source 'http://rubygems.org'
+
+gem 'rake'
+gem "rspec", ">= 2.0.0.beta.19"
+gem 'gemstub', ">= 2.0.0.pre"
+gem 'configatron'
+gem 'mark_facets'
@@ -0,0 +1,40 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ abstract (1.0.0)
+ activesupport (2.3.8)
+ configatron (2.6.3)
+ yamler (>= 0.1.0)
+ diff-lcs (1.1.2)
+ erubis (2.6.6)
+ abstract (>= 1.0.0)
+ gemstub (2.0.0.pre3)
+ activesupport
+ genosaurus
+ mark_facets
+ rspec (>= 2.0.0.beta.19)
+ genosaurus (1.2.4)
+ erubis
+ hashie (0.3.0)
+ mark_facets (0.0.9)
+ hashie
+ rake (0.8.7)
+ rspec (2.0.0.beta.19)
+ rspec-core (= 2.0.0.beta.19)
+ rspec-expectations (= 2.0.0.beta.19)
+ rspec-mocks (= 2.0.0.beta.19)
+ rspec-core (2.0.0.beta.19)
+ rspec-expectations (2.0.0.beta.19)
+ diff-lcs (>= 1.1.2)
+ rspec-mocks (2.0.0.beta.19)
+ yamler (0.1.0)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ configatron
+ gemstub (>= 2.0.0.pre)
+ mark_facets
+ rake
+ rspec (>= 2.0.0.beta.19)
21 LICENSE
@@ -0,0 +1,21 @@
+The MIT License
+
+Copyright (c) 2010 markbates
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
3 README
@@ -0,0 +1,3 @@
+Cover Me - Code Coverage for Ruby 1.9
+========================================================================
+cover_me was developed by: markbates
@@ -0,0 +1,3 @@
+Cover Me - Code Coverage for Ruby 1.9
+========================================================================
+cover_me was developed by: markbates
@@ -0,0 +1,30 @@
+require 'rubygems'
+
+# Set up gems listed in the Gemfile.
+gemfile = File.expand_path('../Gemfile', __FILE__)
+begin
+ ENV['BUNDLE_GEMFILE'] = gemfile
+ require 'bundler'
+ Bundler.setup
+rescue Bundler::GemNotFound => e
+ STDERR.puts e.message
+ STDERR.puts "Try running `bundle install`."
+ exit!
+end if File.exist?(gemfile)
+
+Bundler.require
+
+Gemstub.test_framework = :rspec
+
+Gemstub.gem_spec do |s|
+ s.version = '0.0.1'
+ s.rubyforge_project = 'magrathea'
+ s.add_dependency('configatron')
+ s.add_dependency('hashie')
+ s.email = 'mark+cover_me@markbates.com'
+ s.homepage = 'http://www.metabates.com'
+end
+
+Gemstub.rdoc do |rd|
+ rd.title = 'Cover Me - Code Coverage for Ruby 1.9'
+end
@@ -0,0 +1,35 @@
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = %q{cover_me}
+ s.version = "0.0.1.20100813104028"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["markbates"]
+ s.date = %q{2010-08-13}
+ s.description = %q{cover_me was developed by: markbates}
+ s.email = %q{mark+cover_me@markbates.com}
+ s.extra_rdoc_files = ["README", "LICENSE"]
+ s.files = ["lib/cover_me/config.rb", "lib/cover_me/formatter.rb", "lib/cover_me/hash.rb", "lib/cover_me/html_formatter.rb", "lib/cover_me/index.rb", "lib/cover_me/processor.rb", "lib/cover_me/report.rb", "lib/cover_me/templates/index.css", "lib/cover_me/templates/index.html.erb", "lib/cover_me/templates/jquery.js", "lib/cover_me/templates/jquery.tablesorter.js", "lib/cover_me/templates/report.css", "lib/cover_me/templates/report.html.erb", "lib/cover_me.rb", "README", "LICENSE"]
+ s.homepage = %q{http://www.metabates.com}
+ s.require_paths = ["lib"]
+ s.rubyforge_project = %q{magrathea}
+ s.rubygems_version = %q{1.3.7}
+ s.summary = %q{cover_me}
+
+ if s.respond_to? :specification_version then
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
+ s.specification_version = 3
+
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
+ s.add_runtime_dependency(%q<configatron>, [">= 0"])
+ s.add_runtime_dependency(%q<hashie>, [">= 0"])
+ else
+ s.add_dependency(%q<configatron>, [">= 0"])
+ s.add_dependency(%q<hashie>, [">= 0"])
+ end
+ else
+ s.add_dependency(%q<configatron>, [">= 0"])
+ s.add_dependency(%q<hashie>, [">= 0"])
+ end
+end
@@ -0,0 +1 @@
+I'm the user model!
@@ -0,0 +1 @@
+I am bar.rb!
@@ -0,0 +1 @@
+Hello from Foo Spec!
@@ -0,0 +1 @@
+Hello from Bar Test!
@@ -0,0 +1,31 @@
+# http://engineering.attinteractive.com/2010/08/code-coverage-in-ruby-1-9/
+
+require 'coverage'
+require 'erb'
+require 'fileutils'
+require 'configatron'
+# require 'mark_facets'
+
+module CoverMe
+end
+
+path = File.join(File.dirname(__FILE__), 'cover_me')
+
+require File.expand_path(File.join(path, 'hash'))
+require File.expand_path(File.join(path, 'config'))
+
+CoverMe.set_defaults
+
+%w{index report formatter processor html_formatter}.each do |file|
+ require File.expand_path(File.join(path, file))
+end
+
+# Start the code coverage
+# if ENV['use_coverage']
+ Coverage.start
+
+ at_exit do
+ CoverMe::Processor.new(Coverage.result).process!
+ CoverMe.config.at_exit
+ end
+# end
@@ -0,0 +1,33 @@
+module CoverMe
+
+ class << self
+
+ def config(&block)
+ yield configatron.cover_me if block_given?
+ configatron.cover_me
+ end
+
+ def set_defaults
+ CoverMe.config do |c|
+ c.project.set_default(:root, Configatron::Delayed.new {Rails.root})
+ c.set_default(:file_pattern, Configatron::Delayed.new do
+ /(#{CoverMe.config.project.root}\/app\/.+\.rb|#{CoverMe.config.project.root}\/lib\/.+\.rb)/ix
+ end)
+ c.set_default(:formatter, Configatron::Delayed.new {CoverMe::HtmlFormatter})
+ c.set_default(:at_exit, Configatron::Dynamic.new {
+ if CoverMe.config.formatter == CoverMe::HtmlFormatter
+ index = File.join(CoverMe.config.html_formatter.output_path, 'index.html')
+ if File.exists?(index)
+ `open #{index}`
+ end
+ end
+ })
+ c.html_formatter.set_default(:output_path, Configatron::Delayed.new {File.join(CoverMe.config.project.root, 'coverage')})
+ c.html_formatter.set_default(:finalizer_files, {'report.css' => 'report.css', 'index.css' => 'index.css',
+ 'jquery.js' => 'jquery.js', 'jquery.tablesorter.js' => 'jquery.tablesorter.js'})
+ end
+ end
+
+ end
+
+end
@@ -0,0 +1,24 @@
+class CoverMe::Formatter
+
+ attr_accessor :options
+
+ def initialize(options = {})
+ self.options = options
+ end
+
+ def format(object)
+ if object.is_a?(CoverMe::Report)
+ return send(:format_report, object)
+ elsif object.is_a?(CoverMe::Index)
+ return send(:format_index, object)
+ end
+ end
+
+ def finalize
+ end
+
+ def template(file)
+ ERB.new(File.read(File.join(File.dirname(__FILE__), 'templates', file)))
+ end
+
+end
@@ -0,0 +1,14 @@
+require 'hashie'
+class Hash
+
+ def to_mash
+ h = self.dup
+ h.each do |k, v|
+ if v.is_a?(Hash) && !v.is_a?(Hashie::Mash)
+ h[k] = v.to_mash
+ end
+ end
+ Hashie::Mash.new(h)
+ end
+
+end
@@ -0,0 +1,84 @@
+class CoverMe::HtmlFormatter < CoverMe::Formatter
+
+ def initialize(options = {})
+ super
+ self.options = ({:output_path => CoverMe.config.html_formatter.output_path}.merge(self.options)).to_mash
+ end
+
+ def format_report(report)
+ write_file(report.filename) do |file|
+ file.write(self.template('report.html.erb').result(binding))
+ end
+ end
+
+ def format_index(index)
+ write_file('index') do |file|
+ file.write(self.template('index.html.erb').result(binding))
+ end
+ end
+
+ def finalize
+ super
+ CoverMe.config.html_formatter.finalizer_files.each do |name, t|
+ write_file(name, '') do |file|
+ file.write(self.template(t).result(binding))
+ end
+ end
+ end
+
+ protected
+ def write_file(filename, extension = '.html', &block)
+ path = File.join(self.options.output_path, filename)
+ FileUtils.mkdir_p(File.dirname(path))
+ File.open(path + extension, 'w', &block)
+ end
+
+end
+
+# class CoverMe::Formatter
+#
+# attr_accessor :coverages
+# attr_accessor :index
+# attr_accessor :options
+#
+# def initialize(coverages, options = {})
+# self.coverages = coverages
+# self.index = CoverMe::Index.new
+# self.options = ({:pattern => CoverMe.config.file_pattern}.merge(options)).to_mash
+# end
+#
+# def format
+# report_template = self.template('report.html.erb')
+#
+# self.coverages.map do |filename, coverage|
+# if filename.match(self.options.pattern)
+# report = CoverMe::Report.new(filename.gsub(CoverMe.config.project.root.to_s, ''), coverage)
+# self.index.reports << report
+# source = File.readlines(filename)
+# path = File.join(CoverMe.config.project.root, "coverage", report.filename)
+# FileUtils.mkdir_p(File.dirname(path))
+# File.open(path + '.html', 'w') do |file|
+# file.write(report_template.result(binding))
+# end
+# end
+# end
+#
+# self.write_index
+# end
+#
+# protected
+# def write_index
+# {'index.html' => 'index.html.erb', 'report.css' => 'report.css',
+# 'index.css' => 'index.css', 'jquery.js' => 'jquery.js',
+# 'jquery.tablesorter.js' => 'jquery.tablesorter.js'}.each do |k, v|
+# File.open(File.join(CoverMe.config.project.root, 'coverage', k), 'w') do |file|
+# file.write(self.template(v).result(binding))
+# end
+# end
+# end
+#
+# def template(file)
+# ERB.new(File.read(File.join(File.dirname(__FILE__), 'templates', file)))
+# end
+#
+# end
Oops, something went wrong.

0 comments on commit cc011aa

Please sign in to comment.