[macruby-changes] [2265] MacRuby/trunk/mspec/lib/mspec
source_changes at macosforge.org
source_changes at macosforge.org
Sat Aug 8 17:02:56 PDT 2009
Revision: 2265
http://trac.macosforge.org/projects/ruby/changeset/2265
Author: mattaimonetti at gmail.com
Date: 2009-08-08 17:02:54 -0700 (Sat, 08 Aug 2009)
Log Message:
-----------
added MacRuby formatter
Modified Paths:
--------------
MacRuby/trunk/mspec/lib/mspec/runner/actions.rb
MacRuby/trunk/mspec/lib/mspec/runner/formatters.rb
MacRuby/trunk/mspec/lib/mspec/utils/options.rb
Added Paths:
-----------
MacRuby/trunk/mspec/lib/mspec/runner/actions/macruby_stats.rb
MacRuby/trunk/mspec/lib/mspec/runner/formatters/macruby.rb
Added: MacRuby/trunk/mspec/lib/mspec/runner/actions/macruby_stats.rb
===================================================================
--- MacRuby/trunk/mspec/lib/mspec/runner/actions/macruby_stats.rb (rev 0)
+++ MacRuby/trunk/mspec/lib/mspec/runner/actions/macruby_stats.rb 2009-08-09 00:02:54 UTC (rev 2265)
@@ -0,0 +1,88 @@
+class MacRubySpecStats
+ attr_accessor :categories
+ attr_reader :category, :subcategory, :file
+
+ def initialize
+ @categories = {}
+ end
+
+ def push_file(path)
+ cat, subcat, specfile = parse_path(path)
+ @categories[cat] ||= {}
+ @categories[cat][subcat] ||= {:files => 0, :examples => 0, :expectations => 0, :failures => 0, :errors => 0}
+ @categories[cat][subcat][:files] += 1
+ end
+
+ # increases the amount of examples in the category
+ def example!(path)
+ increase_stats(path, :examples)
+ end
+
+ def expectation!(path)
+ increase_stats(path, :expectations)
+ end
+
+ def failure!(path)
+ increase_stats(path, :failures)
+ end
+
+ def error!(path)
+ increase_stats(path, :errors)
+ end
+
+ protected
+
+ def parse_path(path)
+ path =~ /frozen\/(.+?)\/(.+)\/(.+_spec)\.rb/
+ [$1, $2, $3]
+ end
+
+ def increase_stats(path, type)
+ cat, subcat, specfile = parse_path(path)
+ @categories[cat][subcat][type] += 1
+ end
+
+end
+
+
+class MacRubyStatsAction
+
+ def initialize
+ @stats = MacRubySpecStats.new
+ end
+
+ def register
+ MSpec.register :load, self
+ MSpec.register :exception, self
+ MSpec.register :example, self
+ MSpec.register :expectation, self
+ end
+
+ def unregister
+ MSpec.unregister :load, self
+ MSpec.unregister :exception, self
+ MSpec.unregister :example, self
+ MSpec.unregister :expectation, self
+ end
+
+ def load
+ @stats.push_file MSpec.retrieve(:file)
+ end
+
+ def example(state, block)
+ @stats.example! MSpec.retrieve(:file)
+ end
+
+ def expectation(state)
+ @stats.expectation! MSpec.retrieve(:file)
+ end
+
+ def exception(exception)
+ exception.failure? ? @stats.failure!(MSpec.retrieve(:file)) : @stats.error!(MSpec.retrieve(:file))
+ end
+
+ def categories
+ @stats.categories
+ end
+
+end
\ No newline at end of file
Modified: MacRuby/trunk/mspec/lib/mspec/runner/actions.rb
===================================================================
--- MacRuby/trunk/mspec/lib/mspec/runner/actions.rb 2009-08-08 10:14:39 UTC (rev 2264)
+++ MacRuby/trunk/mspec/lib/mspec/runner/actions.rb 2009-08-09 00:02:54 UTC (rev 2265)
@@ -6,3 +6,4 @@
require 'mspec/runner/actions/tagpurge'
require 'mspec/runner/actions/debug'
require 'mspec/runner/actions/gdb'
+require 'mspec/runner/actions/macruby_stats'
\ No newline at end of file
Added: MacRuby/trunk/mspec/lib/mspec/runner/formatters/macruby.rb
===================================================================
--- MacRuby/trunk/mspec/lib/mspec/runner/formatters/macruby.rb (rev 0)
+++ MacRuby/trunk/mspec/lib/mspec/runner/formatters/macruby.rb 2009-08-09 00:02:54 UTC (rev 2265)
@@ -0,0 +1,49 @@
+require 'mspec/expectations/expectations'
+require 'mspec/runner/formatters/dotted'
+require 'mspec/runner/actions/macruby_stats'
+
+class MacRubyFormatter < DottedFormatter
+ def initialize(out=nil)
+ @exception = @failure = false
+ @exceptions = []
+ @count = 0
+ @out = $stdout
+
+ if out.nil?
+ @finish = $stdout
+ else
+ @finish = File.open out, "w"
+ end
+ end
+
+ def switch
+ @out = @finish
+ end
+
+ def after(state)
+ end
+
+ def register
+ super
+ (@stats = MacRubyStatsAction.new).register
+ end
+
+ def finish
+ switch
+
+ print "\n"
+ @stats.categories.each do |category, subcategories|
+ print "#{category}:\n"
+ subcategories.each do |subcat, stats|
+ print " #{subcat} stats: #{stats[:failures]} failures, #{stats[:errors]} errors (#{stats[:examples]} examples, #{stats[:expectations]} expectations, #{stats[:files]} files) \n"
+
+ end
+ end
+ print "\nSummary:\n"
+ print "files: ", @tally.counter.files, "\n"
+ print "examples: ", @tally.counter.examples, "\n"
+ print "expectations: ", @tally.counter.expectations, "\n"
+ print "failures: ", @tally.counter.failures, "\n"
+ print "errors: ", @tally.counter.errors, "\n"
+ end
+end
Modified: MacRuby/trunk/mspec/lib/mspec/runner/formatters.rb
===================================================================
--- MacRuby/trunk/mspec/lib/mspec/runner/formatters.rb 2009-08-08 10:14:39 UTC (rev 2264)
+++ MacRuby/trunk/mspec/lib/mspec/runner/formatters.rb 2009-08-09 00:02:54 UTC (rev 2265)
@@ -8,3 +8,4 @@
require 'mspec/runner/formatters/spinner'
require 'mspec/runner/formatters/method'
require 'mspec/runner/formatters/yaml'
+require 'mspec/runner/formatters/macruby'
Modified: MacRuby/trunk/mspec/lib/mspec/utils/options.rb
===================================================================
--- MacRuby/trunk/mspec/lib/mspec/utils/options.rb 2009-08-08 10:14:39 UTC (rev 2264)
+++ MacRuby/trunk/mspec/lib/mspec/utils/options.rb 2009-08-09 00:02:54 UTC (rev 2265)
@@ -276,6 +276,8 @@
config[:formatter] = MethodFormatter
when 'y', 'yaml'
config[:formatter] = YamlFormatter
+ when 'mr', 'macruby'
+ config[:formatter] = MacRubyFormatter
else
puts "Unknown format: #{o}"
puts @parser
@@ -293,6 +295,7 @@
doc " a, *, spin SpinnerFormatter"
doc " t, method MethodFormatter"
doc " y, yaml YamlFormatter\n"
+ doc " mr, macruby MacRubyFormatter\n"
on("-o", "--output", "FILE",
"Write formatter output to FILE") do |f|
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090808/821d156d/attachment-0001.html>
More information about the macruby-changes
mailing list