require "rbconfig" # This generator bootstraps a Rails project for use with Cucumber class CucumberGenerator < Rails::Generator::Base DEFAULT_SHEBANG = File.join(Config::CONFIG["bindir"], Config::CONFIG["ruby_install_name"]) attr_accessor :framework, :language def initialize(runtime_args, runtime_options = {}) super @features_path = "features" end def manifest if options[:language] @language = options[:language] set_language(@language) end record do |m| m.directory "features/support" m.file "env.rb", "features/support/env.rb" m.directory File.join(@features_path, "step_definitions") if @language m.file File.join(@language, "webrat_steps.rb"), File.join(@features_path, "step_definitions", "paths.rb") m.file File.join(@language, "webrat_steps.rb"), File.join(@features_path, "step_definitions", "webrat_steps.rb") else m.file "webrat_steps.rb", File.join(@features_path, "step_definitions", "webrat_steps.rb") m.file "paths.rb", "features/support/paths.rb" end m.directory "lib/tasks" m.template "cucumber.rake", "lib/tasks/cucumber.rake" m.file "cucumber", "script/cucumber", { :chmod => 0755, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang] } end end def framework options[:framework] || :rspec end protected def banner "Usage: #{$0} cucumber" end # Load up the transations for the passed language, and modify the features_path accordingly def set_language(language) @features_path = File.join(@features_path, language) end def add_options!(opt) opt.separator '' opt.separator 'Options:' opt.on('--rspec', 'Setup cucumber for use with RSpec (default)') do |value| options[:framework] = :rspec end opt.on('--testunit', 'Setup cucumber for use with test/unit') do |value| options[:framework] = :testunit end opt.on("-l", "--language=lang", String, "Use a [language] subdirectoy in /features.") do |value| options[:language] = value end end end