templates/rake.erb in cukedep-0.0.8 vs templates/rake.erb in cukedep-0.1.03
- old
+ new
@@ -1,161 +1,185 @@
-# File: <%=rakefile%>
-# Generated by Cukedep <%=Cukedep::Version%> on <%=Time.now.strftime('%d/%m/%Y %H:%M:%S')%>
-
-require 'rake'
-
-# Run Cucumber via specialized Rake task
-require 'cucumber/rake/task'
-# UGLY workaround for bug in Cucumber's rake task
-if Gem::VERSION[0].to_i >= 2 && Cucumber::VERSION <= '1.3.2'
- # Monkey-patch a buggy method
- class Cucumber::Rake::Task::ForkedCucumberRunner
- def gem_available?(gemname)
- if Gem::VERSION[0].to_i >= 2
- gem_available_new_rubygems?(gemname)
- else
- gem_available_old_rubygems?(gemname)
- end
- end
- end # class
-end
-
-# Create a task called cucumber
-Cucumber::Rake::Task.new do |t|
-end
-
-
-# Constant holding the location of the original feature files
-SOURCE_DIR = '<%=source_dir%>'
-
-# Constant holding the location of the project
-CUKE_PROJECT = '<%=proj_dir%>'
-
-# Helper method. Calculate the filepath of a file with given name
-# if it is located in the source dir.
-def source_path_of(aFilename)
- SOURCE_DIR + '/' + aFilename
-end
-
-# Helper method. Calculate the filepath of a file with given name
-# if it is located in the project featurers dir.
-def project_path_of(aFilename)
- CUKE_PROJECT + '/features/' + aFilename
-end
-
-# Helper method. Given the name of files in the source dir, copy them
-# into the project dir.
-def copy_to_project(filenames)
- filenames.each do |fname|
- source_path = source_path_of(fname)
- dest_path = project_path_of(fname)
- FileUtils.copy_file(source_path, dest_path)
- end
-end
-
-
-# Helper method. Given the name of files in the features dir of the project,
-# copy them into the source dir.
-def copy_from_project(*filenames)
- filenames.each do |fname|
- source_path = project_path_of(fname)
- dest_path = source_path_of(fname)
- FileUtils.copy_file(source_path, dest_path)
- end
-end
-
-def del_from_project(filenames)
- filenames.each do |fname|
- dest_path = project_path_of(fname)
- FileUtils.remove_file(dest_path)
- end
-end
-
-# Helper method. Delete all the files in the
-# the project's features dir that match one of
-# the file name pattern
-def clean_project_dir(fname_patterns)
- curr_dir = Dir.getwd()
- begin
- Dir.chdir(CUKE_PROJECT + '/features')
- fname_patterns.each do |patt|
- filenames = Dir.glob(patt)
- filenames.each { |fn| FileUtils.remove_file(fn) }
- end
- ensure #Always restore previous working dir.
- Dir.chdir(curr_dir)
- end
-end
-
-
-def process_files(filenames)
- copy_to_project(filenames)
- curr_dir = Dir.getwd()
- Dir.chdir(CUKE_PROJECT)
- begin
- do_cuke = Rake::Task[:cucumber]
- do_cuke.reenable
- do_cuke.invoke
- ensure
- Dir.chdir(curr_dir)
- end
- del_from_project(filenames)
-end
-
-def process_a_feature(filename)
- process_files([filename])
-end
-
-
-AllUnidentifiedFeatures = [<%anonymous_list = anonymous.map { |name| "'#{name}'"}%>
- <%=anonymous_list.join(",\n ")%>
-]
-
-
-AllFeatureIdentifiers = [ <%identifier_list = feature_ids.map {|f_id| ":#{f_id}"}%>
- <%=identifier_list.join(",\n ")%>
-]
-
-# Default rake task is also top-level task
-task :default => :run_all_features
-
-
-desc 'Run all features'
-task :run_all_features => [:before_all, :all_features, :after_all] do
- ; # Do nothing
-end
-
-
-# Remove feature files from a cuke project
-task :dir_cleanup do
- clean_project_dir(['*.feature'])
-end
-
-
-
-desc 'Before all'
-task :before_all => [:dir_cleanup] do
- ; # Do nothing
-end
-
-desc 'After_all'
-task :after_all do
- ; # Do nothing
-end
-
-
-task :unidentified do
- process_files(AllUnidentifiedFeatures)
-end
-
-# Tasks for feature files involved in dependencies
-<%deps.each do |dep|%>
-<%dep_list = dep.dependents.map { |ff| ":#{ff.feature.identifier}" } %>
-task :<%=dep.dependee.feature.identifier%> <%= dep_list.empty? ? '' : %Q|=> [#{dep_list.join(', ') }]| %> do
- process_a_feature('<%=dep.dependee.basename%>')
-end
-<%end%>
-
-task :all_features => ([:unidentified] + AllFeatureIdentifiers) do
-end
-
+# File: <%=rakefile%>
+# Generated by Cukedep <%=Cukedep::Version%> on <%=Time.now.strftime('%d/%m/%Y %H:%M:%S')%>
+
+require 'rake'
+
+<%require 'pathname'
+ # In case of development version, use classes from the project direct
+ # Otherwise rely on code from gem.
+ rake_dir = Pathname.new(Dir.getwd)
+ cukedep_dir = Pathname.new(Cukedep::RootDir).realdirpath
+ development_env = nil # Will be true iff w. dir is child of Cukedep project dir.
+ rake_dir.ascend do |a_parent|
+ development_env = true if a_parent.realdirpath == cukedep_dir
+ end
+ if development_env
+ rel_path = cukedep_dir.relative_path_from(rake_dir)%>
+# Use development codebase
+require_relative '<%=rel_path.to_s + '/lib/cukedep/file-action'%>'
+<% else%>
+require 'cukedep/file-action'
+<% end%>
+
+# Run Cucumber via specialized Rake task
+require 'cucumber/rake/task'
+# UGLY workaround for bug in Cucumber's rake task
+if Gem::VERSION[0].to_i >= 2 && Cucumber::VERSION <= '1.3.2'
+ # Monkey-patch a buggy method
+ class Cucumber::Rake::Task::ForkedCucumberRunner
+ def gem_available?(gemname)
+ if Gem::VERSION[0].to_i >= 2
+ gem_available_new_rubygems?(gemname)
+ else
+ gem_available_old_rubygems?(gemname)
+ end
+ end
+ end # class
+end
+
+# Create a task called cucumber
+Cucumber::Rake::Task.new do |t|
+end
+
+#######################################
+# Retrieving state at end of Cukedep::Application#run! method
+#######################################
+
+# Constant holding the location of the original feature files
+SOURCE_DIR = '<%=source_dir%>'
+
+# Constant holding the location of the Cucumber project
+CUKE_PROJECT = '<%=proj_dir%>'
+
+# The list of all "legacy" feature file (feature files without the @feature: tag)
+AllUnidentifiedFeatures = [<%anonymous_list = anonymous.map { |name| "'#{name}'"}%>
+ <%=anonymous_list.join(",\n ")%>
+]
+
+# The list of all encountered feature ids
+AllFeatureIdentifiers = [ <%identifier_list = feature_ids.map {|f_id| ":#{f_id}"}%>
+ <%=identifier_list.join(",\n ")%>
+]
+
+
+def run_builtin_actions(anEvent)
+ actions = Cukedep::ActionTriplet.builtin(anEvent)
+ actions.run!(SOURCE_DIR, CUKE_PROJECT) unless actions.nil?
+end
+
+# Helper method. Calculate the filepath of a file with given name
+# if it is located in the source dir.
+def source_path_of(aFilename)
+ SOURCE_DIR + '/' + aFilename
+end
+
+# Helper method. Calculate the filepath of a file with given name
+# if it is located in the project features dir.
+def project_path_of(aFilename)
+ CUKE_PROJECT + '/features/' + aFilename
+end
+
+# Helper method. Given the name of files in the source dir, copy them
+# into the project dir.
+def copy_to_project(filenames)
+ filenames.each do |fname|
+ source_path = source_path_of(fname)
+ dest_path = project_path_of(fname)
+ FileUtils.copy_file(source_path, dest_path)
+ end
+end
+
+
+# Helper method. Given the name of files in the features dir of the project,
+# copy them into the source dir.
+def copy_from_project(*filenames)
+ filenames.each do |fname|
+ source_path = project_path_of(fname)
+ dest_path = source_path_of(fname)
+ FileUtils.copy_file(source_path, dest_path)
+ end
+end
+
+# Helper method. Delete all the files in the
+# the project's features dir that match one of
+# the file name pattern
+def clean_project_dir(fname_patterns)
+ curr_dir = Dir.getwd()
+ begin
+ Dir.chdir(CUKE_PROJECT + '/features')
+ fname_patterns.each do |patt|
+ filenames = Dir.glob(patt)
+ filenames.each { |fn| FileUtils.remove_file(fn) }
+ end
+ ensure #Always restore previous working dir.
+ Dir.chdir(curr_dir)
+ end
+end
+
+
+# Helper method. Invoke Cucumber with the given project root dir.
+# Assumption: all features files to execute are placed
+# in the appropriate folder.
+def invoke_cuke(projectDir)
+ curr_dir = Dir.getwd()
+ Dir.chdir(projectDir)
+ begin
+ do_cuke = Rake::Task[:cucumber]
+ do_cuke.reenable
+ do_cuke.invoke
+ ensure
+ Dir.chdir(curr_dir)
+ end
+end
+
+
+def process_files(filenames)
+ run_builtin_actions(:before_each)
+ copy_to_project(filenames)
+ invoke_cuke(CUKE_PROJECT)
+ run_builtin_actions(:after_each)
+ #del_from_project(filenames)
+end
+
+def process_a_feature(filename)
+ process_files([filename])
+end
+
+
+# Default rake task is also top-level task
+task :default => :run_all_features
+
+
+desc 'Run all features'
+task :run_all_features => [:before_all, :all_features, :after_all] do
+ ; # Do nothing
+end
+
+
+desc 'Before all'
+task :before_all do
+ run_builtin_actions(:before_all)
+end
+
+desc 'After_all'
+task :after_all do
+ run_builtin_actions(:after_all)
+end
+
+
+task :unidentified do
+ process_files(AllUnidentifiedFeatures)
+end
+
+# Tasks for feature files involved in dependencies
+<%deps.each do |dep|%>
+<%dep_list = dep.dependents.map { |ff| ":#{ff.feature.identifier}" } %>
+desc "<%=dep.dependee.feature.identifier%>: run <%=dep.dependee.basename%>"
+task :<%=dep.dependee.feature.identifier%> <%= dep_list.empty? ? '' : %Q|=> [#{dep_list.join(', ') }]| %> do
+ process_a_feature('<%=dep.dependee.basename%>')
+end
+<%end%>
+
+task :all_features => ([:unidentified] + AllFeatureIdentifiers) do
+end
+
# End of file
\ No newline at end of file