From be54303fa93025342526a522fb7322e19a7642ad Mon Sep 17 00:00:00 2001 From: "maul.esel" Date: Mon, 2 Sep 2013 14:00:58 +0200 Subject: [PATCH 1/4] Use File#read instead of #readlines.join construct --- features/step_definitions/jekyll_steps.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/features/step_definitions/jekyll_steps.rb b/features/step_definitions/jekyll_steps.rb index a1a1b797..483e61ec 100644 --- a/features/step_definitions/jekyll_steps.rb +++ b/features/step_definitions/jekyll_steps.rb @@ -142,11 +142,11 @@ Then /^the (.*) directory should exist$/ do |dir| end Then /^I should see "(.*)" in "(.*)"$/ do |text, file| - assert Regexp.new(text).match(File.open(file).readlines.join) + assert Regexp.new(text).match(File.read(file)) end Then /^I should see exactly "(.*)" in "(.*)"$/ do |text, file| - assert_equal text, File.open(file).readlines.join.strip + assert_equal text, File.read(file).strip end Then /^I should not see "(.*)" in "(.*)"$/ do |text, file| @@ -154,7 +154,7 @@ Then /^I should not see "(.*)" in "(.*)"$/ do |text, file| end Then /^I should see escaped "(.*)" in "(.*)"$/ do |text, file| - assert Regexp.new(Regexp.escape(text)).match(File.open(file).readlines.join) + assert Regexp.new(Regexp.escape(text)).match(File.read(file)) end Then /^the "(.*)" file should exist$/ do |file| @@ -166,9 +166,9 @@ 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(Regexp.escape(Time.now.to_s)), File.read(file) end Then /^I should see today's date in "(.*)"$/ do |file| - assert_match Regexp.new(Date.today.to_s), File.open(file).readlines.join + assert_match Regexp.new(Date.today.to_s), File.read(file) end From 89f0d69b07af8f9e4aac176b5e21b0bf0b939727 Mon Sep 17 00:00:00 2001 From: "maul.esel" Date: Sat, 7 Sep 2013 18:07:54 +0200 Subject: [PATCH 2/4] Revert to #readlines#join, but enclose it in a function This is necessary to preserve the handling of \r\n and \n line endings. --- features/step_definitions/jekyll_steps.rb | 12 ++++++------ features/support/env.rb | 6 ++++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/features/step_definitions/jekyll_steps.rb b/features/step_definitions/jekyll_steps.rb index 483e61ec..cc8353e0 100644 --- a/features/step_definitions/jekyll_steps.rb +++ b/features/step_definitions/jekyll_steps.rb @@ -142,19 +142,19 @@ Then /^the (.*) directory should exist$/ do |dir| end Then /^I should see "(.*)" in "(.*)"$/ do |text, file| - assert Regexp.new(text).match(File.read(file)) + assert Regexp.new(text).match(read_file(file)) end Then /^I should see exactly "(.*)" in "(.*)"$/ do |text, file| - assert_equal text, File.read(file).strip + assert_equal text, read_file(file).strip end Then /^I should not see "(.*)" in "(.*)"$/ do |text, file| - assert_no_match Regexp.new(text), File.read(file) + assert_no_match Regexp.new(text), read_file(file) end Then /^I should see escaped "(.*)" in "(.*)"$/ do |text, file| - assert Regexp.new(Regexp.escape(text)).match(File.read(file)) + assert Regexp.new(Regexp.escape(text)).match(read_file(file)) end Then /^the "(.*)" file should exist$/ do |file| @@ -166,9 +166,9 @@ 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.read(file) + assert_match Regexp.new(Regexp.escape(Time.now.to_s)), read_file(file) end Then /^I should see today's date in "(.*)"$/ do |file| - assert_match Regexp.new(Date.today.to_s), File.read(file) + assert_match Regexp.new(Date.today.to_s), read_file(file) end diff --git a/features/support/env.rb b/features/support/env.rb index efe6b1b6..dfab55c8 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -35,5 +35,11 @@ def location(folder, direction) [before || '.', after || '.'] end +def read_file(path) + File.open(path) do |file| + file.readlines.join # avoid differences with \n and \r\n line endings + end +end + # work around "invalid option: --format" cucumber bug (see #296) Test::Unit.run = true if RUBY_VERSION < '1.9' From 3a18157d204fcc5b28e496707756e632037aec36 Mon Sep 17 00:00:00 2001 From: "maul.esel" Date: Tue, 10 Sep 2013 19:09:33 +0200 Subject: [PATCH 3/4] rename the new function --- features/step_definitions/jekyll_steps.rb | 12 ++++++------ features/support/env.rb | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/features/step_definitions/jekyll_steps.rb b/features/step_definitions/jekyll_steps.rb index cc8353e0..66ae8eaf 100644 --- a/features/step_definitions/jekyll_steps.rb +++ b/features/step_definitions/jekyll_steps.rb @@ -142,19 +142,19 @@ Then /^the (.*) directory should exist$/ do |dir| end Then /^I should see "(.*)" in "(.*)"$/ do |text, file| - assert Regexp.new(text).match(read_file(file)) + assert Regexp.new(text).match(file_contents(file)) end Then /^I should see exactly "(.*)" in "(.*)"$/ do |text, file| - assert_equal text, read_file(file).strip + assert_equal text, file_contents(file).strip end Then /^I should not see "(.*)" in "(.*)"$/ do |text, file| - assert_no_match Regexp.new(text), read_file(file) + assert_no_match Regexp.new(text), file_contents(file) end Then /^I should see escaped "(.*)" in "(.*)"$/ do |text, file| - assert Regexp.new(Regexp.escape(text)).match(read_file(file)) + assert Regexp.new(Regexp.escape(text)).match(file_contents(file)) end Then /^the "(.*)" file should exist$/ do |file| @@ -166,9 +166,9 @@ 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)), read_file(file) + assert_match Regexp.new(Regexp.escape(Time.now.to_s)), file_contents(file) end Then /^I should see today's date in "(.*)"$/ do |file| - assert_match Regexp.new(Date.today.to_s), read_file(file) + assert_match Regexp.new(Date.today.to_s), file_contents(file) end diff --git a/features/support/env.rb b/features/support/env.rb index dfab55c8..e426a4ab 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -35,7 +35,7 @@ def location(folder, direction) [before || '.', after || '.'] end -def read_file(path) +def file_contents(path) File.open(path) do |file| file.readlines.join # avoid differences with \n and \r\n line endings end From f20b7d8bd299756295dc1a7506997f0967b3703d Mon Sep 17 00:00:00 2001 From: "maul.esel" Date: Thu, 12 Sep 2013 20:19:56 +0200 Subject: [PATCH 4/4] use assert_match --- features/step_definitions/jekyll_steps.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/features/step_definitions/jekyll_steps.rb b/features/step_definitions/jekyll_steps.rb index 66ae8eaf..21f24062 100644 --- a/features/step_definitions/jekyll_steps.rb +++ b/features/step_definitions/jekyll_steps.rb @@ -142,7 +142,7 @@ Then /^the (.*) directory should exist$/ do |dir| end Then /^I should see "(.*)" in "(.*)"$/ do |text, file| - assert Regexp.new(text).match(file_contents(file)) + assert_match Regexp.new(text), file_contents(file) end Then /^I should see exactly "(.*)" in "(.*)"$/ do |text, file| @@ -154,7 +154,7 @@ Then /^I should not see "(.*)" in "(.*)"$/ do |text, file| end Then /^I should see escaped "(.*)" in "(.*)"$/ do |text, file| - assert Regexp.new(Regexp.escape(text)).match(file_contents(file)) + assert_match Regexp.new(Regexp.escape(text)), file_contents(file) end Then /^the "(.*)" file should exist$/ do |file|