# 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 # End of file