Skip to content

Commit

Permalink
Doing some refactorings to keep the code DRY (as aslak suggested ;-P)
Browse files Browse the repository at this point in the history
  • Loading branch information
Roman Gonzalez committed Oct 27, 2008
1 parent 048138a commit 2b1f576
Showing 1 changed file with 30 additions and 39 deletions.
69 changes: 30 additions & 39 deletions lib/cucumber/rake/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,39 @@ def initialize(task_name = "features", desc = "Run Features with Cucumber")
yield self if block_given?

@feature_pattern = "features/**/*.feature" if feature_pattern.nil? && feature_list.nil?
@step_pattern = "features/**/*.rb" if step_pattern.nil? && step_list.nil?
@step_pattern = "features/**/*.rb" if step_pattern.nil? && step_list.nil?
@binary ||= File.expand_path(File.dirname(__FILE__) + '/../../../bin/cucumber')
define_tasks
define_task
end

def define_tasks
def define_task
desc @desc
task @task_name do
lib_args = ['"%s"' % ([LIB] + libs).join(File::PATH_SEPARATOR)]
cucumber_bin = ['"%s"' % binary]
cuc_opts = [(ENV['CUCUMBER_OPTS'] || cucumber_opts)]
ruby(arguments_for_ruby_execution.join(" ")) # ruby(*args) is broken on Windows
end
end

step_files.each do |step_file|
cuc_opts << '--require'
cuc_opts << step_file
end
def arguments_for_ruby_execution(task_args = nil)
lib_args = ['"%s"' % ([LIB] + libs).join(File::PATH_SEPARATOR)]
cucumber_bin = ['"%s"' % binary]
cuc_opts = [(ENV['CUCUMBER_OPTS'] || cucumber_opts)]

if rcov
args = (['-I'] + lib_args + ['-S', 'rcov'] + rcov_opts + cucumber_bin + ['--'] + cuc_opts + feature_files).flatten
else
args = (['-I'] + lib_args + cucumber_bin + cuc_opts + feature_files).flatten
end
ruby(args.join(" ")) # ruby(*args) is broken on Windows
step_files(task_args).each do |step_file|
cuc_opts << '--require'
cuc_opts << step_file
end

if rcov
args = (['-I'] + lib_args + ['-S', 'rcov'] + rcov_opts +
cucumber_bin + ['--'] + cuc_opts + feature_files(task_args)).flatten
else
args = (['-I'] + lib_args + cucumber_bin + cuc_opts + feature_files(task_args)).flatten
end

args
end


def feature_files # :nodoc:
def feature_files(task_args = nil) # :nodoc:
if ENV['FEATURE']
FileList[ ENV['FEATURE'] ]
else
Expand All @@ -61,13 +66,13 @@ def feature_files # :nodoc:
end
end

def step_files # :nodoc:
def step_files(task_args = nil) # :nodoc:
if ENV['STEPS']
FileList[ ENV['STEPS'] ]
else
result = []
result += step_list.to_a if step_list
result += FileList[step_pattern].to_a if step_pattern
result += Array(step_list) if step_list
result += Array(FileList[step_pattern]) if step_pattern
FileList[result]
end
end
Expand All @@ -79,29 +84,15 @@ def initialize(task_name = "feature", desc = "Run an specified feature with Cucu
super(task_name, desc)
end

def define_tasks
def define_task
desc @desc
task @task_name, :feature_name do |t, args|
lib_args = ['"%s"' % ([LIB] + libs).join(File::PATH_SEPARATOR)]
cucumber_bin = ['"%s"' % binary]
cuc_opts = [(ENV['CUCUMBER_OPTS'] || cucumber_opts)]

step_files.each do |step_file|
cuc_opts << '--require'
cuc_opts << step_file
end

if rcov
args = (['-I'] + lib_args + ['-S', 'rcov'] + rcov_opts + cucumber_bin + ['--'] + cuc_opts + feature_files(args[:feature_name])).flatten
else
args = (['-I'] + lib_args + cucumber_bin + cuc_opts + feature_files(args[:feature_name])).flatten
end
ruby(args.join(" ")) # ruby(*args) is broken on Windows
ruby(arguments_for_ruby_execution(args).join(" ")) # ruby(*args) is broken on Windows
end
end

def feature_files(feature) # :nodoc:
FileList[File.join("features", "**", "#{feature}.feature")] if !feature.nil?
def feature_files(task_arguments) # :nodoc:
FileList[File.join("features", "**", "#{task_arguments[:feature_name]}.feature")]
end

end
Expand Down

0 comments on commit 2b1f576

Please sign in to comment.