# File: cukedep.rake # Generated by Cukedep 0.1.09 on 02/04/2015 21:15:29 require 'rake' # Use development codebase require_relative '../../../lib/cukedep/file-action' # 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 = 'C:/Ruby193/lib/ruby/site_ruby/Cukedep/spec/cukedep/sample_features' # Constant holding the location of the Cucumber project CUKE_PROJECT = 'C:/Ruby193/lib/ruby/site_ruby/Cukedep/sample' # The list of all "legacy" feature file (feature files without the @feature: tag) AllUnidentifiedFeatures = [ 'standalone.feature' ] # The list of all encountered feature ids AllFeatureIdentifiers = [ :qux, :quux, :corge, :foo, :baz, :bar ] 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 desc "qux: run a_few_tests.feature" task :qux do process_a_feature('a_few_tests.feature') end desc "quux: run more_tests.feature" task :quux do process_a_feature('more_tests.feature') end desc "corge: run other_tests.feature" task :corge => [:foo] do process_a_feature('other_tests.feature') end desc "foo: run some_tests.feature" task :foo => [:bar, :qux] do process_a_feature('some_tests.feature') end desc "baz: run still_other_tests.feature" task :baz do process_a_feature('still_other_tests.feature') end desc "bar: run yet_other_tests.feature" task :bar => [:baz, :qux, :quux] do process_a_feature('yet_other_tests.feature') end task :all_features => ([:unidentified] + AllFeatureIdentifiers) do end # End of file