From e02173425bd3e2021c5b474275ff3c793bb906e5 Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Tue, 29 Nov 2011 14:17:07 -0800 Subject: [PATCH] reorg cucumber steps so gem extensions can reuse them --- features/step_definitions/builder_steps.rb | 52 ------------------- features/support/env.rb | 6 +-- lib/middleman/step_definitions.rb | 6 +++ .../step_definitions/builder_steps.rb | 45 ++++++++++++++++ .../step_definitions/generator_steps.rb | 12 ++--- .../step_definitions/server_steps.rb | 6 +-- 6 files changed, 63 insertions(+), 64 deletions(-) delete mode 100644 features/step_definitions/builder_steps.rb create mode 100644 lib/middleman/step_definitions.rb create mode 100644 lib/middleman/step_definitions/builder_steps.rb rename {features => lib/middleman}/step_definitions/generator_steps.rb (50%) rename features/step_definitions/middleman_steps.rb => lib/middleman/step_definitions/server_steps.rb (92%) diff --git a/features/step_definitions/builder_steps.rb b/features/step_definitions/builder_steps.rb deleted file mode 100644 index 9b82acb0..00000000 --- a/features/step_definitions/builder_steps.rb +++ /dev/null @@ -1,52 +0,0 @@ -require 'fileutils' - -Given /^app "([^"]*)" is using config "([^"]*)"$/ do |path, config_name| - root = File.dirname(File.dirname(File.dirname(__FILE__))) - target = File.join(root, "fixtures", path) - config_path = File.join(target, "config-#{config_name}.rb") - config_dest = File.join(target, "config.rb") - FileUtils.cp(config_path, config_dest) -end - -Given /^a built app at "([^"]*)"$/ do |path| - root = File.dirname(File.dirname(File.dirname(__FILE__))) - target = File.join(root, "fixtures", path) - - build_target = File.join(target, "build") - FileUtils.rm_rf(build_target) - - build_cmd = File.expand_path(File.join(root, "bin", "middleman build")) - `cd #{target} && #{build_cmd}` -end - -Then /^cleanup built app at "([^"]*)"$/ do |path| - root = File.dirname(File.dirname(File.dirname(__FILE__))) - target = File.join(root, "fixtures", path, "build") - FileUtils.rm_rf(target) -end - -Given /^a built app at "([^"]*)" with flags "([^"]*)"$/ do |path, flags| - root = File.dirname(File.dirname(File.dirname(__FILE__))) - target = File.join(root, "fixtures", path) - build_cmd = File.expand_path(File.join(root, "bin", "middleman build")) - `cd #{target} && #{build_cmd} #{flags}` -end - -Then /^"([^"]*)" should exist at "([^"]*)"$/ do |target_file, path| - root = File.dirname(File.dirname(File.dirname(__FILE__))) - target = File.join(root, "fixtures", path, "build", target_file) - File.exists?(target).should be_true -end - -Then /^"([^"]*)" should exist at "([^"]*)" and include "([^"]*)"$/ do |target_file, path, expected| - root = File.dirname(File.dirname(File.dirname(__FILE__))) - target = File.join(root, "fixtures", path, "build", target_file) - File.exists?(target).should be_true - File.read(target).should include(expected) -end - -Then /^"([^"]*)" should not exist at "([^"]*)"$/ do |target_file, path| - root = File.dirname(File.dirname(File.dirname(__FILE__))) - target = File.join(root, "fixtures", path, "build", target_file) - File.exists?(target).should be_false -end \ No newline at end of file diff --git a/features/support/env.rb b/features/support/env.rb index 7c016118..587dd388 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -1,3 +1,3 @@ -root_path = File.dirname(File.dirname(File.dirname(__FILE__))) -require File.join(root_path, 'lib', 'middleman') -require "rack/test" \ No newline at end of file +PROJECT_ROOT_PATH = File.dirname(File.dirname(File.dirname(__FILE__))) +require File.join(PROJECT_ROOT_PATH, 'lib', 'middleman') +require File.join(PROJECT_ROOT_PATH, 'lib', 'middleman', 'step_definitions') \ No newline at end of file diff --git a/lib/middleman/step_definitions.rb b/lib/middleman/step_definitions.rb new file mode 100644 index 00000000..c1959d4e --- /dev/null +++ b/lib/middleman/step_definitions.rb @@ -0,0 +1,6 @@ +MIDDLEMAN_ROOT_PATH = File.dirname(File.dirname(File.dirname(__FILE__))) +MIDDLEMAN_BIN_PATH = File.join(MIDDLEMAN_ROOT_PATH, "bin") + +require "middleman/step_definitions/builder_steps" +require "middleman/step_definitions/generator_steps" +require "middleman/step_definitions/server_steps" \ No newline at end of file diff --git a/lib/middleman/step_definitions/builder_steps.rb b/lib/middleman/step_definitions/builder_steps.rb new file mode 100644 index 00000000..8f48c64a --- /dev/null +++ b/lib/middleman/step_definitions/builder_steps.rb @@ -0,0 +1,45 @@ +require 'fileutils' + +Given /^app "([^\"]*)" is using config "([^\"]*)"$/ do |path, config_name| + target = File.join(PROJECT_ROOT_PATH, "fixtures", path) + config_path = File.join(target, "config-#{config_name}.rb") + config_dest = File.join(target, "config.rb") + FileUtils.cp(config_path, config_dest) +end + +Given /^a built app at "([^\"]*)"$/ do |path| + target = File.join(PROJECT_ROOT_PATH, "fixtures", path) + + build_target = File.join(target, "build") + FileUtils.rm_rf(build_target) + + build_cmd = File.join(MIDDLEMAN_BIN_PATH, "middleman build") + `cd #{target} && #{build_cmd}` +end + +Then /^cleanup built app at "([^\"]*)"$/ do |path| + target = File.join(PROJECT_ROOT_PATH, "fixtures", path, "build") + FileUtils.rm_rf(target) +end + +Given /^a built app at "([^\"]*)" with flags "([^\"]*)"$/ do |path, flags| + target = File.join(PROJECT_ROOT_PATH, "fixtures", path) + build_cmd = File.join(MIDDLEMAN_BIN_PATH, "middleman build") + `cd #{target} && #{build_cmd} #{flags}` +end + +Then /^"([^\"]*)" should exist at "([^\"]*)"$/ do |target_file, path| + target = File.join(PROJECT_ROOT_PATH, "fixtures", path, "build", target_file) + File.exists?(target).should be_true +end + +Then /^"([^\"]*)" should exist at "([^\"]*)" and include "([^\"]*)"$/ do |target_file, path, expected| + target = File.join(PROJECT_ROOT_PATH, "fixtures", path, "build", target_file) + File.exists?(target).should be_true + File.read(target).should include(expected) +end + +Then /^"([^\"]*)" should not exist at "([^\"]*)"$/ do |target_file, path| + target = File.join(PROJECT_ROOT_PATH, "fixtures", path, "build", target_file) + File.exists?(target).should be_false +end \ No newline at end of file diff --git a/features/step_definitions/generator_steps.rb b/lib/middleman/step_definitions/generator_steps.rb similarity index 50% rename from features/step_definitions/generator_steps.rb rename to lib/middleman/step_definitions/generator_steps.rb index 5e134d0e..b1d8d32d 100644 --- a/features/step_definitions/generator_steps.rb +++ b/lib/middleman/step_definitions/generator_steps.rb @@ -1,14 +1,14 @@ require 'fileutils' Given /^generated directory at "([^\"]*)"$/ do |dirname| - target = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "fixtures", dirname) - init_cmd = File.expand_path(File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "bin", "middleman init")) + target = File.join(PROJECT_ROOT_PATH, "fixtures", dirname) + init_cmd = File.join(MIDDLEMAN_BIN_PATH, "middleman init") `cd #{File.dirname(target)} && #{init_cmd} #{File.basename(target)}` end Then /^template files should exist at "([^\"]*)"$/ do |dirname| - target = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "fixtures", dirname) - template_glob = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "lib", "middleman", "templates", "default", "*/**/*") + target = File.join(PROJECT_ROOT_PATH, "fixtures", dirname) + template_glob = File.join(MIDDLEMAN_ROOT_PATH, "lib", "middleman", "templates", "default", "*/**/*") Dir[template_glob].each do |f| next if File.directory?(f) @@ -17,7 +17,7 @@ Then /^template files should exist at "([^\"]*)"$/ do |dirname| end Then /^empty directories should exist at "([^\"]*)"$/ do |dirname| - target = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "fixtures", dirname) + target = File.join(PROJECT_ROOT_PATH, "fixtures", dirname) %w(source/stylesheets source/javascripts source/images).each do |d| File.exists?("#{target}/#{d}").should be_true @@ -25,6 +25,6 @@ Then /^empty directories should exist at "([^\"]*)"$/ do |dirname| end Then /^cleanup at "([^\"]*)"$/ do |dirname| - target = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "fixtures", dirname) + target = File.join(PROJECT_ROOT_PATH, "fixtures", dirname) FileUtils.rm_rf(target) end \ No newline at end of file diff --git a/features/step_definitions/middleman_steps.rb b/lib/middleman/step_definitions/server_steps.rb similarity index 92% rename from features/step_definitions/middleman_steps.rb rename to lib/middleman/step_definitions/server_steps.rb index 933a06ad..d0f44041 100644 --- a/features/step_definitions/middleman_steps.rb +++ b/lib/middleman/step_definitions/server_steps.rb @@ -1,3 +1,5 @@ +require "rack/test" + Given /^a clean server$/ do @initialize_commands = [] end @@ -20,11 +22,9 @@ Given /^current environment is "([^\"]*)"$/ do |env| end Given /^the Server is running at "([^\"]*)"$/ do |app_path| - root_dir = File.dirname(File.dirname(File.dirname(__FILE__))) - initialize_commands = @initialize_commands || [] initialize_commands.unshift lambda { - set :root, File.join(root_dir, "fixtures", app_path) + set :root, File.join(PROJECT_ROOT_PATH, "fixtures", app_path) set :environment, @current_env || :development }