From aa6ee14fb7b6fa808c29898640a21c67f99b9c51 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Fri, 27 Sep 2013 15:38:38 -0400 Subject: [PATCH 1/4] Get some nice Regexp which is agnostic about the seconds. --- features/step_definitions/jekyll_steps.rb | 2 +- features/support/env.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/features/step_definitions/jekyll_steps.rb b/features/step_definitions/jekyll_steps.rb index 56da1d11..81d68da9 100644 --- a/features/step_definitions/jekyll_steps.rb +++ b/features/step_definitions/jekyll_steps.rb @@ -170,7 +170,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.open(file).readlines.join + assert_match Regexp.new(seconds_agnostic_time(Time.now)), File.open(file).readlines.join end Then /^I should see today's date in "(.*)"$/ do |file| diff --git a/features/support/env.rb b/features/support/env.rb index 5c7db508..5c550fe4 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -40,5 +40,15 @@ def location(folder, direction) [before || '.', after || '.'] end +def seconds_agnostic_time(datetime = Time.now) + pieces = datetime.to_s.split(" ") + time = "#{pieces[1].split(':').first}:#{pieces[1].split(':')[1]}:\\d{2}" + [ + Regexp.escape(pieces[0]), + time, + Regexp.escape(pieces.last) + ].join("\\ ") +end + # work around "invalid option: --format" cucumber bug (see #296) Test::Unit.run = true if RUBY_VERSION < '1.9' From 2dd7964926306c1850906d92e079802fa5c73123 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Fri, 27 Sep 2013 21:56:24 -0400 Subject: [PATCH 2/4] C'mon, you're a Ruby developer. What are you doing. --- features/support/env.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/features/support/env.rb b/features/support/env.rb index 5c550fe4..0d296d76 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -41,12 +41,12 @@ def location(folder, direction) end def seconds_agnostic_time(datetime = Time.now) - pieces = datetime.to_s.split(" ") - time = "#{pieces[1].split(':').first}:#{pieces[1].split(':')[1]}:\\d{2}" + date, time, zone = datetime.strftime("%Y-%m-%d %H:%M:%S %z").split(" ") + hours, minutes, _ = time.split(":") [ - Regexp.escape(pieces[0]), - time, - Regexp.escape(pieces.last) + Regexp.escape(date), + "#{hour}:#{minutes}:\\d{2}", + Regexp.escape(zone) ].join("\\ ") end From d958fd5679837b8362984474b8f52901ecca0c3c Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sat, 28 Sep 2013 13:26:55 -0400 Subject: [PATCH 3/4] Clean it up, clean it up. --- features/support/env.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/features/support/env.rb b/features/support/env.rb index 0d296d76..70437a79 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -41,11 +41,10 @@ def location(folder, direction) end def seconds_agnostic_time(datetime = Time.now) - date, time, zone = datetime.strftime("%Y-%m-%d %H:%M:%S %z").split(" ") - hours, minutes, _ = time.split(":") + date, time, zone = datetime.strftime("%Y-%m-%d %H:%M %z").split(" ") [ Regexp.escape(date), - "#{hour}:#{minutes}:\\d{2}", + "#{time}:\\d{2}", Regexp.escape(zone) ].join("\\ ") end From 425885460fb62c3587d0ce7e3ad3fc17d66d0849 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sat, 28 Sep 2013 14:16:57 -0400 Subject: [PATCH 4/4] DARN YOU RUBY 1.8.7 AND YOUR DIFFERENT TIME.TO_S METHOD --- features/support/env.rb | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/features/support/env.rb b/features/support/env.rb index 70437a79..7760bc3f 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -40,8 +40,16 @@ def location(folder, direction) [before || '.', after || '.'] end -def seconds_agnostic_time(datetime = Time.now) - date, time, zone = datetime.strftime("%Y-%m-%d %H:%M %z").split(" ") +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}", @@ -49,5 +57,13 @@ def seconds_agnostic_time(datetime = Time.now) ].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'