Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Working html and pretty formatters

  • Loading branch information...
commit 8340b84017710702c1e4388f3dd57a149fe7ed5d 1 parent 0cafbe5
@moredip authored
View
3  lib/timestamped-scenarios.rb
@@ -1,3 +0,0 @@
-module Timestamped
- # Your code goes here...
-end
View
25 lib/timestamped/adds_timestamp.rb
@@ -0,0 +1,25 @@
+module Timestamped
+ module AddsTimestamp
+
+ # we'll assume that the test run starts around the time this
+ # file is evaluated. Pretty hacky, and not terribly accurate, but
+ # I think it's good enough
+ TEST_RUN_START = Time.now
+
+ def self.formatter_with_timestamped_scenario_names(formatter_class)
+ Class.new( formatter_class ){ include AddsTimestamp }
+ end
+
+ def scenario_name(keyword, name, file_colon_line, source_indent)
+ name = append_timestamp_to(name)
+ super( keyword, name, file_colon_line, source_indent )
+ end
+
+
+ def append_timestamp_to( name )
+ ts = Time.now - TEST_RUN_START
+ formatted_timestamp = "%i:%02i" % [ts.to_i/60,(ts%60).round]
+ "#{name} [#{formatted_timestamp}]"
+ end
+ end
+end
View
7 lib/timestamped/html_formatter.rb
@@ -0,0 +1,7 @@
+require 'timestamped/adds_timestamp'
+
+require 'cucumber/formatter/html'
+module Timestamped
+ HtmlFormatter = AddsTimestamp.formatter_with_timestamped_scenario_names(Cucumber::Formatter::Html)
+end
+
View
7 lib/timestamped/pretty_formatter.rb
@@ -0,0 +1,7 @@
+require 'timestamped/adds_timestamp'
+
+require 'cucumber/formatter/pretty'
+module Timestamped
+ PrettyFormatter = AddsTimestamp.formatter_with_timestamped_scenario_names(Cucumber::Formatter::Pretty)
+end
+
View
2  lib/timestamped-scenarios/version.rb → lib/timestamped/version.rb
@@ -1,3 +1,3 @@
module Timestamped
- VERSION = "0.0.1"
+ VERSION = "0.1.0"
end
View
4 timestamped-scenarios.gemspec
@@ -1,6 +1,6 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
-require "timestamped-scenarios/version"
+require "timestamped/version"
Gem::Specification.new do |s|
s.name = "timestamped-scenarios"
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
s.summary = %q{A custom cucumber formatter which appends a timestamp to each scenario's name as it is executed}
s.description = %q{A custom cucumber formatter which appends a timestamp to each scenario's name as it is executed}
- s.rubyforge_project = "timestamped-scenarios"
+ s.add_dependency "cucumber"
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
Please sign in to comment.
Something went wrong with that request. Please try again.