diff --git a/lib/flowerbox.rb b/lib/flowerbox.rb index 8a983bb..c87628e 100644 --- a/lib/flowerbox.rb +++ b/lib/flowerbox.rb @@ -20,6 +20,12 @@ module Flowerbox autoload :Rack, 'flowerbox/rack' + autoload :ResultSet, 'flowerbox/result_set' + autoload :GatheredResult, 'flowerbox/gathered_result' + autoload :Result, 'flowerbox/result' + autoload :Failure, 'flowerbox/failure' + autoload :Exception, 'flowerbox/exception' + class << self def spec_patterns @spec_patterns ||= [] @@ -64,11 +70,14 @@ module Flowerbox Tilt::CoffeeScriptTemplate.default_bare = Flowerbox.bare_coffeescript - result = Flowerbox.runner_environment.collect do |env| - env.run(build_sprockets_for(dir)) + result_set = ResultSet.new + + Flowerbox.runner_environment.each do |env| + result_set << env.run(build_sprockets_for(dir)) end - result.max + result_set.print + result_set.exitstatus end def build_sprockets_for(dir) diff --git a/lib/flowerbox/exception.rb b/lib/flowerbox/exception.rb new file mode 100644 index 0000000..5b15fec --- /dev/null +++ b/lib/flowerbox/exception.rb @@ -0,0 +1,15 @@ +module Flowerbox + class Exception < Result + attr_reader :message + + def initialize(message) + @message = message + end + + def print + puts message + puts + end + end +end + diff --git a/lib/flowerbox/failure.rb b/lib/flowerbox/failure.rb new file mode 100644 index 0000000..a5f851a --- /dev/null +++ b/lib/flowerbox/failure.rb @@ -0,0 +1,22 @@ +module Flowerbox + class Failure < Result + attr_reader :name, :message, :file + + def initialize(name, message, file) + @name, @message, @file = name, message, file + end + + def runners + @runners ||= [] + end + + def ==(other) + @name == other.name && @message == other.message + end + + def to_s + "#{message} [#{runners.join(',')}] (#{file})" + end + end +end + diff --git a/lib/flowerbox/gathered_result.rb b/lib/flowerbox/gathered_result.rb new file mode 100644 index 0000000..893d8ff --- /dev/null +++ b/lib/flowerbox/gathered_result.rb @@ -0,0 +1,28 @@ +module Flowerbox + class GatheredResult + attr_reader :name + + def initialize(name) + @name = name + end + + def <<(result) + results << result + end + + def results + @results ||= [] + end + + def print + puts name.join(' ') + + results.each do |result| + puts " #{result}" + end + + puts + end + end +end + diff --git a/lib/flowerbox/result.rb b/lib/flowerbox/result.rb new file mode 100644 index 0000000..1efeb91 --- /dev/null +++ b/lib/flowerbox/result.rb @@ -0,0 +1,6 @@ +module Flowerbox + class Result + + end +end + diff --git a/lib/flowerbox/result_set.rb b/lib/flowerbox/result_set.rb new file mode 100644 index 0000000..ae0c1dd --- /dev/null +++ b/lib/flowerbox/result_set.rb @@ -0,0 +1,67 @@ +module Flowerbox + class ResultSet + attr_reader :results, :options + + def self.from_failures(failures, options) + results = failures.collect do |result_data| + if name = result_data.first['splitName'] + result_data.collect do |failure| + Failure.new(name, failure['message'], failure['trace']['stack'].first) + end + else + Exception.new(result_data['trace']['stack']) + end + end.flatten + + results.each { |result| result.runners << options[:runner] } + + new(results, options) + end + + def initialize(results = [], options = {}) + @results, @options = results, options + end + + def <<(other) + other.results.each do |other_result| + if existing_result = results.find { |result| result == other_result } + existing_result.runners << other_result.runners + else + results << other_result + end + end + end + + def exitstatus + @results.empty? ? 0 : 1 + end + + def print + gathered_results.each(&:print) + end + + def gathered_results + return @gathered_results if @gathered_results + + @gathered_results = [] + + results.each do |result| + case result + when Flowerbox::Exception + @gathered_results << result + when Flowerbox::Failure + if !(gathered_result = @gathered_results.find { |g| g.name == result.name }) + gathered_result = GatheredResult.new(result.name) + + @gathered_results << gathered_result + end + + gathered_result << result + end + end + + @gathered_results + end + end +end + diff --git a/lib/flowerbox/runner/base.rb b/lib/flowerbox/runner/base.rb index 27adaa4..7c7db22 100644 --- a/lib/flowerbox/runner/base.rb +++ b/lib/flowerbox/runner/base.rb @@ -18,32 +18,7 @@ module Flowerbox puts - failures.each do |failure_set| - if failure_set.first['splitName'] - puts failure_set.first['splitName'].join(' ') - end - - failure_set.each do |failure| - case failure['trace']['stack'] - when String - # exception - puts failure['trace']['stack'] - else - # failed test - puts %{#{failure['message']} (#{failure['trace']['stack'].first})} - end - end - - puts - end - - puts "#{total_count} tests, #{failure_count} failures, #{time.to_f / 1000} sec" - - if failures.length == 0 - $?.exitstatus - else - 1 - end + ResultSet.from_failures(failures, :runner => name, :time => time) end def type