diff --git a/features/step_definitions/jekyll_steps.rb b/features/step_definitions/jekyll_steps.rb index 169f522e..7a74486b 100644 --- a/features/step_definitions/jekyll_steps.rb +++ b/features/step_definitions/jekyll_steps.rb @@ -181,7 +181,7 @@ Then /^the "(.*)" file should not exist$/ do |file| end Then /^I should see today's time in "(.*)"$/ do |file| - assert_match Regexp.new(Regexp.escape(Time.now.to_s)), file_contents(file) + assert_match Regexp.new(seconds_agnostic_time(Time.now)), file_contents(file) end Then /^I should see today's date in "(.*)"$/ do |file| diff --git a/features/support/env.rb b/features/support/env.rb index e414ad6f..5ccbab98 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -46,5 +46,30 @@ def file_contents(path) end end +def seconds_agnostic_datetime(datetime = Time.now) + pieces = datetime.to_s.split(" ") + if pieces.size == 6 # Ruby 1.8.7 + date = pieces[0..2].join(" ") + time = seconds_agnostic_time(pieces[3]) + zone = pieces[4..5].join(" ") + else # Ruby 1.9.1 or greater + date, time, zone = pieces + time = seconds_agnostic_time(time) + end + [ + Regexp.escape(date), + "#{time}:\\d{2}", + Regexp.escape(zone) + ].join("\\ ") +end + +def seconds_agnostic_time(time) + if time.is_a? Time + time = time.strftime("%H:%M:%S") + end + hour, minutes, _ = time.split(":") + "#{hour}:#{minutes}" +end + # work around "invalid option: --format" cucumber bug (see #296) Test::Unit.run = true if RUBY_VERSION < '1.9'