[macruby-changes] [4446] MacRuby/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Sun Aug 22 07:32:29 PDT 2010
Revision: 4446
http://trac.macosforge.org/projects/ruby/changeset/4446
Author: eloy.de.enige at gmail.com
Date: 2010-08-22 07:32:26 -0700 (Sun, 22 Aug 2010)
Log Message:
-----------
Accidentlly removed macruby mspec result formmatter. Also add rake spec:rubyspec task.
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
MacRuby/trunk/rakelib/spec.rake
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 2010-08-22 14:32:26 UTC (rev 4446)
@@ -0,0 +1,104 @@
+class MacRubySpecStats
+ attr_accessor :categories
+ attr_reader :category, :subcategory, :file, :tag_files
+
+ def initialize
+ @categories = {}
+ @tag_files = []
+ end
+
+ # return the current arborescence
+ def push_file(path)
+ category = parse_path(path)
+ @categories[category] ||= {:files => 0, :examples => 0, :expectations => 0, :failures => 0, :errors => 0, :skipped => 0}
+ @categories[category][:files] += 1
+ category
+ end
+
+ def push_skipped(category, amount)
+ increase_stats(category, :skipped, amount)
+ end
+
+ # increases the amount of examples in the category
+ def example!(category)
+ increase_stats(category, :examples)
+ end
+
+ def expectation!(category)
+ increase_stats(category, :expectations)
+ end
+
+ def failure!(category)
+ increase_stats(category, :failures)
+ end
+
+ def error!(category)
+ increase_stats(category, :errors)
+ end
+
+ protected
+
+ # Return the spec category
+ def parse_path(path)
+ /spec\/(frozen|macruby)\/(.+?)\// =~ path
+ $2
+ end
+
+ def increase_stats(category, type, amount=1)
+ @categories[category][type] += amount
+ end
+
+end
+
+
+class MacRubyStatsAction
+
+ attr_reader :current_category
+
+ 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
+ @current_category = @stats.push_file(MSpec.retrieve(:file))
+ skilled_specs = MSpec.read_tags(['critical', 'fails']).size
+ @stats.push_skipped(current_category, skilled_specs) if skilled_specs > 0
+ print "."
+ end
+
+ def example(state, block)
+ @stats.example!(current_category)
+ end
+
+ def expectation(state)
+ @stats.expectation!(current_category)
+ end
+
+ def exception(exception)
+ exception.failure? ? @stats.failure!(current_category) : @stats.error!(current_category)
+ end
+
+ def categories
+ @stats.categories
+ end
+
+ def tags
+ @stats.tag_files
+ end
+
+end
+
Modified: MacRuby/trunk/mspec/lib/mspec/runner/actions.rb
===================================================================
--- MacRuby/trunk/mspec/lib/mspec/runner/actions.rb 2010-08-22 13:19:38 UTC (rev 4445)
+++ MacRuby/trunk/mspec/lib/mspec/runner/actions.rb 2010-08-22 14:32:26 UTC (rev 4446)
@@ -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'
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 2010-08-22 14:32:26 UTC (rev 4446)
@@ -0,0 +1,73 @@
+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 sum_skipped
+ @stats.categories.inject(0){|sum, cat_info| sum += cat_info.last[:skipped].to_i}
+ end
+
+ def gen_rate(passed, skipped)
+ "%0.2f" % [passed* (100 / (passed + skipped).to_f)]
+ end
+
+ def finish
+ switch
+
+ @stats.categories.each do |key, details|
+ puts ""
+ puts "#{key.capitalize}:"
+ puts " files: #{details[:files]}"
+ puts " examples: #{details[:examples]}"
+ puts " skipped examples: #{details[:skipped]}"
+ puts " expectations: #{details[:expectations]}"
+ puts " failures: #{details[:failures]}"
+ puts " errors: #{details[:errors]}"
+ puts " pass rate: #{gen_rate(details[:examples], details[:skipped])}%"
+ end
+
+ puts "\nSummary:"
+ puts " files: #{@tally.counter.files}"
+ puts " examples: #{@tally.counter.examples}"
+ puts " skipped examples: #{sum_skipped}"
+ puts " expectations: #{@tally.counter.expectations}"
+ puts " failures: #{@tally.counter.failures}"
+ puts " errors: #{@tally.counter.errors}"
+ puts " pass rate: #{gen_rate(@tally.counter.examples, sum_skipped)}%"
+
+ print "\nExceptions:\n" unless @exceptions.empty?
+ count = 0
+ @exceptions.each do |exc|
+ outcome = exc.failure? ? "FAILED" : "ERROR"
+ print "\n#{count += 1})\n#{exc.description} #{outcome}\n"
+ print exc.message, "\n"
+ print exc.backtrace, "\n"
+ end
+ end
+end
+
Modified: MacRuby/trunk/mspec/lib/mspec/runner/formatters.rb
===================================================================
--- MacRuby/trunk/mspec/lib/mspec/runner/formatters.rb 2010-08-22 13:19:38 UTC (rev 4445)
+++ MacRuby/trunk/mspec/lib/mspec/runner/formatters.rb 2010-08-22 14:32:26 UTC (rev 4446)
@@ -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 2010-08-22 13:19:38 UTC (rev 4445)
+++ MacRuby/trunk/mspec/lib/mspec/utils/options.rb 2010-08-22 14:32:26 UTC (rev 4446)
@@ -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
@@ -292,7 +294,8 @@
doc " m, summary SummaryFormatter"
doc " a, *, spin SpinnerFormatter"
doc " t, method MethodFormatter"
- doc " y, yaml YamlFormatter\n"
+ doc " y, yaml YamlFormatter"
+ doc " mr, macruby MacRubyFormatter\n"
on("-o", "--output", "FILE",
"Write formatter output to FILE") do |f|
Modified: MacRuby/trunk/rakelib/spec.rake
===================================================================
--- MacRuby/trunk/rakelib/spec.rake 2010-08-22 13:19:38 UTC (rev 4445)
+++ MacRuby/trunk/rakelib/spec.rake 2010-08-22 14:32:26 UTC (rev 4446)
@@ -29,6 +29,11 @@
mspec :ci, ":macruby"
end
+ desc "Run all RubySpec-only specs"
+ task :rubyspec do
+ mspec :ci, ":rubyspec"
+ end
+
desc "Run all Language-only specs"
task :language do
mspec :ci, ":language"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100822/e3ecf437/attachment.html>
More information about the macruby-changes
mailing list