class AuthenticationFeaturesGenerator < Rails::Generator::Base
  def manifest
    record do |m|
      m.dependency 'cucumber', [], :collision => :skip

      # generate the .feature files
      Dir.entries(File.join(File.dirname(__FILE__), 'templates', 'features')).each do |file_name|
        m.file(File.join('features', file_name), File.join('features', file_name)) if file_name.match(/\.feature$/)
      end

      # generate authentication step definitions
      Dir.entries(File.join(File.dirname(__FILE__), 'templates', 'features', 'step_definitions')).each do |file_name|
        m.file(File.join('features', 'step_definitions', file_name), File.join('features', 'step_definitions', file_name)) if file_name.match(/\.rb$/)
      end

      # generate authentication support/paths
      # FIXME: when the generator is run this should ideally not replicate itself
      m.gsub_file File.join('features', 'support', 'paths.rb'), /case page_name/ do |match|
        "#{match}\n#{File.read(File.join(File.dirname(__FILE__), 'templates', 'features', 'support', 'authentication_paths.rb'))}"
      end
    end
  end
end

class AuthenticationFeaturesGenerator < Rails::Generator::Base
  def manifest
    record do |m|
      m.dependency 'cucumber', [], :collision => :skip
      m.dependency 'rspec', [], :collision => :skip

      # generate the .feature files
      Dir.entries(File.join(File.dirname(__FILE__), 'templates', 'features')).each do |file_name|
        m.file(File.join('features', file_name), File.join('features', file_name)) if file_name.match(/\.feature$/)
      end

      # generate authentication step definitions
      Dir.entries(File.join(File.dirname(__FILE__), 'templates', 'features', 'step_definitions')).each do |file_name|
        m.file(File.join('features', 'step_definitions', file_name), File.join('features', 'step_definitions', file_name)) if file_name.match(/\.rb$/)
      end

      # generate authentication support/paths
      # FIXME: when the generator is run this should ideally not replicate itself
      m.gsub_file File.join('features', 'support', 'paths.rb'), /case page_name/ do |match|
        "#{match}\n#{File.read(File.join(File.dirname(__FILE__), 'templates', 'features', 'support', 'authentication_paths.rb'))}"
      end

      # we use object_daddy for both features and specs and it is probably a good idea to give the application a copy of them
      m.directory(File.join('spec', 'exemplars'))
      m.file(File.join('..', '..', '..', 'spec', 'exemplars', 'user_exemplar.rb'), File.join('spec', 'exemplars', 'user_exemplar.rb'))
      m.file(File.join('..', '..', '..', 'spec', 'exemplars', 'login_exemplar.rb'), File.join('spec', 'exemplars', 'login_exemplar.rb'))
    end
  end
end

Copy the object_daddy exemplars over to the main application so the cucumber features aren't as angry
Copy the object_daddy exemplars over to the main application so the cucumber features aren't as angry
