From fe66beacc3986e0b77d0c8f2b563f99a34bc92e8 Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Wed, 23 Sep 2015 16:20:16 -0700 Subject: [PATCH] Test fix WIP --- middleman-core/features/collections.feature | 3 +- .../step_definitions/builder_steps.rb | 47 ---------------- .../step_definitions/middleman_steps.rb | 53 ++++++++++++++++++- .../lib/middleman-core/util/data.rb | 4 +- .../source/stylesheets/_partial.sass | 2 + 5 files changed, 56 insertions(+), 53 deletions(-) create mode 100644 middleman-core/source/stylesheets/_partial.sass diff --git a/middleman-core/features/collections.feature b/middleman-core/features/collections.feature index 053986fd..e12ca0a5 100644 --- a/middleman-core/features/collections.feature +++ b/middleman-core/features/collections.feature @@ -197,11 +197,10 @@ Feature: Collections Given a fixture app "collections-app" And a file named "config.rb" with: """ - Dir.chdir(ENV['MM_ROOT']) ignore "/description_template.html" live { - Dir["descriptions/*.txt"] + Dir[File.join(root, "descriptions/*.txt")] }.each do |description_name| base = File.basename(description_name, '.txt') proxy "#{base}.html", "/description_template.html", locals: { diff --git a/middleman-core/lib/middleman-core/step_definitions/builder_steps.rb b/middleman-core/lib/middleman-core/step_definitions/builder_steps.rb index 3293c082..dc0b7c6d 100644 --- a/middleman-core/lib/middleman-core/step_definitions/builder_steps.rb +++ b/middleman-core/lib/middleman-core/step_definitions/builder_steps.rb @@ -4,34 +4,6 @@ Before do @modification_times = Hash.new end -Given /^app "([^\"]*)" is using config "([^\"]*)"$/ do |path, config_name| - target = File.join(PROJECT_ROOT_PATH, 'fixtures', path) - config_path = File.join(expand_path("."), "config-#{config_name}.rb") - config_dest = File.join(expand_path("."), 'config.rb') - FileUtils.cp(config_path, config_dest) -end - -Given /^an empty app$/ do - step %Q{a directory named "empty_app"} - step %Q{I cd to "empty_app"} - ENV['MM_ROOT'] = nil -end - -Given /^a fixture app "([^\"]*)"$/ do |path| - ENV['MM_ROOT'] = nil - - # This step can be reentered from several places but we don't want - # to keep re-copying and re-cd-ing into ever-deeper directories - next if File.basename(expand_path(".")) == path - - step %Q{a directory named "#{path}"} - - target_path = File.join(PROJECT_ROOT_PATH, 'fixtures', path) - FileUtils.cp_r(target_path, expand_path(".")) - - step %Q{I cd to "#{path}"} -end - Given /^a built app at "([^\"]*)"$/ do |path| step %Q{a fixture app "#{path}"} step %Q{I run `middleman build --verbose`} @@ -56,22 +28,3 @@ Given /^a successfully built app at "([^\"]*)" with flags "([^\"]*)"$/ do |path, step %Q{a built app at "#{path}" with flags "#{flags}"} step %Q{was successfully built} end - -Given /^a modification time for a file named "([^\"]*)"$/ do |file| - target = File.join(expand_path("."), file) - @modification_times[target] = File.mtime(target) -end - -Then /^the file "([^\"]*)" should not have been updated$/ do |file| - target = File.join(expand_path("."), file) - expect(File.mtime(target)).to eq(@modification_times[target]) -end - -# Provide this Aruba overload in case we're matching something with quotes in it -Then /^the file "([^"]*)" should contain '([^']*)'$/ do |file, partial_content| - expect(file).to have_file_content(Regexp.new(Regexp.escape(partial_content)), true) -end - -And /the file "(.*)" should be gzipped/ do |file| - expect(File.binread(File.join(expand_path("."), file), 2)).to eq(['1F8B'].pack('H*')) -end diff --git a/middleman-core/lib/middleman-core/step_definitions/middleman_steps.rb b/middleman-core/lib/middleman-core/step_definitions/middleman_steps.rb index 8b2690cb..63236a10 100644 --- a/middleman-core/lib/middleman-core/step_definitions/middleman_steps.rb +++ b/middleman-core/lib/middleman-core/step_definitions/middleman_steps.rb @@ -1,11 +1,60 @@ +require 'fileutils' + +Given /^app "([^\"]*)" is using config "([^\"]*)"$/ do |path, config_name| + target = File.join(PROJECT_ROOT_PATH, 'fixtures', path) + config_path = File.join(expand_path("."), "config-#{config_name}.rb") + config_dest = File.join(expand_path("."), 'config.rb') + FileUtils.cp(config_path, config_dest) +end + +Given /^an empty app$/ do + step %Q{a directory named "empty_app"} + step %Q{I cd to "empty_app"} + ENV['MM_ROOT'] = nil +end + +Given /^a fixture app "([^\"]*)"$/ do |path| + ENV['MM_ROOT'] = nil + + # This step can be reentered from several places but we don't want + # to keep re-copying and re-cd-ing into ever-deeper directories + next if File.basename(expand_path(".")) == path + + step %Q{a directory named "#{path}"} + + target_path = File.join(PROJECT_ROOT_PATH, 'fixtures', path) + FileUtils.cp_r(target_path, expand_path(".")) + + step %Q{I cd to "#{path}"} +end + Then /^the file "([^\"]*)" has the contents$/ do |path, contents| - File.write(File.expand_path(path), contents) + write_file(path, contents) @server_inst.files.find_new_files! end Then /^the file "([^\"]*)" is removed$/ do |path| - File.delete(File.expand_path(path)) + step %Q{I remove the file "#{path}"} @server_inst.files.find_new_files! end + +Given /^a modification time for a file named "([^\"]*)"$/ do |file| + target = File.join(expand_path("."), file) + @modification_times[target] = File.mtime(target) +end + +Then /^the file "([^\"]*)" should not have been updated$/ do |file| + target = File.join(expand_path("."), file) + expect(File.mtime(target)).to eq(@modification_times[target]) +end + +# Provide this Aruba overload in case we're matching something with quotes in it +Then /^the file "([^"]*)" should contain '([^']*)'$/ do |file, partial_content| + expect(file).to have_file_content(Regexp.new(Regexp.escape(partial_content)), true) +end + +And /the file "(.*)" should be gzipped/ do |file| + expect(File.binread(File.join(expand_path("."), file), 2)).to eq(['1F8B'].pack('H*')) +end diff --git a/middleman-core/lib/middleman-core/util/data.rb b/middleman-core/lib/middleman-core/util/data.rb index c26439fb..e05d4d82 100644 --- a/middleman-core/lib/middleman-core/util/data.rb +++ b/middleman-core/lib/middleman-core/util/data.rb @@ -41,9 +41,9 @@ module Middleman::Util::Data end case [start, stop] - when %w[--- ---], %w[--- ...] + when %w(--- ---), %w(--- ...) [parse_yaml(frontmatter, full_path), additional_content] - when %w[;;; ;;;] + when %w(;;; ;;;) [parse_json(frontmatter, full_path), additional_content] else [{}, content] diff --git a/middleman-core/source/stylesheets/_partial.sass b/middleman-core/source/stylesheets/_partial.sass new file mode 100644 index 00000000..d3e1f391 --- /dev/null +++ b/middleman-core/source/stylesheets/_partial.sass @@ -0,0 +1,2 @@ +body + font-size: 14px \ No newline at end of file