Skip to content

Commit

Permalink
Support Cucumber 3
Browse files Browse the repository at this point in the history
  • Loading branch information
cgriego authored and tpope committed Jul 20, 2018
1 parent e327499 commit 54a873e
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 6 deletions.
22 changes: 16 additions & 6 deletions lib/fivemat.rb
Expand Up @@ -2,13 +2,24 @@

module Fivemat
autoload :Cucumber, 'fivemat/cucumber'
autoload :Cucumber3, 'fivemat/cucumber3'
autoload :MiniTest, 'fivemat/minitest/unit'
autoload :RSpec, 'fivemat/rspec'
autoload :RSpec3, 'fivemat/rspec3'
autoload :Spec, 'fivemat/spec'

# Cucumber 2 detects the formatter API based on initialize arity
def initialize(runtime, path_or_io, options)
def cucumber3?
defined?(::Cucumber) && ::Cucumber::VERSION >= '3'
end
module_function :cucumber3?

# Cucumber detects the formatter API based on initialize arity
if cucumber3?
def initialize(config)
end
else
def initialize(runtime, path_or_io, options)
end
end

def rspec3?
Expand All @@ -34,16 +45,15 @@ def self.new(*args)
case args.size
when 0 then MiniTest::Unit
when 1 then
if rspec3?
if args.first.class.to_s == "Cucumber::Configuration"
Cucumber3
elsif rspec3?
RSpec3
else
RSpec
end
when 2 then Spec
when 3
if ::Cucumber::VERSION >= '3'
abort "Fivemat does not yet support Cucumber 3"
end
Cucumber
else
raise ArgumentError
Expand Down
52 changes: 52 additions & 0 deletions lib/fivemat/cucumber3.rb
@@ -0,0 +1,52 @@
require 'cucumber/formatter/progress'

module Fivemat
class Cucumber3 < ::Cucumber::Formatter::Progress
include ElapsedTime

def on_test_case_started(event)
super
feature = event.test_case.feature

unless same_feature_as_previous_test_case?(feature)
after_feature unless @current_feature.nil?
before_feature(feature)
end
end

def on_test_run_finished(_event)
after_feature
after_suite
end

private

def before_feature(feature)
@io.print "#{feature} "
@io.flush
@current_feature = feature
@start_time = Time.now
end

def after_feature
print_elapsed_time @io, @start_time
@io.puts
@io.flush

print_elements(@pending_step_matches, :pending, 'steps')
print_elements(@failed_results, :failed, 'steps')

@pending_step_matches = []
@failed_results = []
end

def after_suite
@io.puts
print_summary
end

def same_feature_as_previous_test_case?(feature)
@current_feature && @current_feature.location == feature.location
end
end
end

0 comments on commit 54a873e

Please sign in to comment.