Sha256: c08bde2e877b58149d9ca1cacc848feae10c4070eecee9d2de6e235acf0413ab

Contents?: true

Size: 1.43 KB

Versions: 1

Compression:

Stored size: 1.43 KB

Contents

# This generator bootstraps a Rails project for use with Cucumber
class FeatureGenerator < Rails::Generator::NamedBase
  attr_reader :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 File.join(@features_path, "step_definitions")
      m.template  "feature.erb", File.join(@features_path, "manage_#{plural_name}.feature")
      m.template  "steps.erb", File.join(@features_path, "step_definitions", "#{singular_name}_steps.rb")    
    end
  end

  class NamedArg
    attr_reader :name

    def initialize(s)
      @name, @type = *s.split(":")
    end

    def value(n)
      if @type == "boolean"
        (n % 2) == 0
      else
        "#{@name} #{n}"
      end
    end
  end

  def named_args
    args.map{|arg| NamedArg.new(arg)}
  end

  protected

  def banner
    "Usage: #{$0} feature ModelName [field:type, field:type]"
  end
  
  def add_options!(opt)
    opt.separator ""
    opt.separator "Options:"
    opt.on("-l", "--language=lang", String, "Use a [language] subdirectoy in /features.") { |v| options[:language] = v }
   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

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kosmas58-cucumber-0.1.99.21 rails_generators/feature/feature_generator.rb