Skip to content
Browse files

Support RSpec 1

  • Loading branch information...
1 parent e6da41a commit c98a39b1717a03b4fcaa1f558f29dd64a5ad1c9d @cgriego committed Apr 21, 2012
Showing with 55 additions and 0 deletions.
  1. +2 −0 lib/fivemat.rb
  2. +53 −0 lib/fivemat/spec.rb
View
2 lib/fivemat.rb
@@ -2,11 +2,13 @@ module Fivemat
autoload :Cucumber, 'fivemat/cucumber'
autoload :MiniTest, 'fivemat/minitest/unit'
autoload :RSpec, 'fivemat/rspec'
+ autoload :Spec, 'fivemat/spec'
def self.new(*args)
case args.size
when 0 then MiniTest::Unit
when 1 then RSpec
+ when 2 then Spec
when 3 then Cucumber
else
raise ArgumentError
View
53 lib/fivemat/spec.rb
@@ -0,0 +1,53 @@
+require 'spec/runner/formatter/progress_bar_formatter'
+
+module Fivemat
+ class Spec < ::Spec::Runner::Formatter::ProgressBarFormatter
+ def initialize(*)
+ super
+ @dumping = false
+ @example_group_number = 0
+ @failed_examples = []
+ @failure_index_offset = 1
+ @last_nested_descriptions = []
+ @last_root_example_group = nil
+ end
+
+ def example_group_started(example_group_proxy)
+ super
+ @example_group_number += 1
+
+ unless example_group_proxy.nested_descriptions.first == @last_nested_descriptions.first
+ @last_root_example_group = example_group_proxy
+ example_group_finished(example_group_proxy) unless @example_group_number == 1
+ output.print "#{example_group_proxy.nested_descriptions.first} "
+ end
+
+ @last_nested_descriptions = example_group_proxy.nested_descriptions
+ end
+
+ def example_group_finished(example_group_proxy)
+ puts
+
+ @failed_examples.each_with_index do |example, index|
+ dump_failure(@failure_index_offset + index, example)
+ end
+
+ @failure_index_offset += @failed_examples.size
+ @failed_examples.clear
+ end
+
+ def example_failed(example, counter, failure)
+ super
+ @failed_examples << failure
+ end
+
+ def start_dump
+ example_group_finished(@last_root_example_group)
+ @dumping = true
+ end
+
+ def dump_failure(*)
+ super unless @dumping
+ end
+ end
+end

0 comments on commit c98a39b

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