Skip to content

Commit

Permalink
Author: H.J. Blok <hj.blok@gmail.com>
Browse files Browse the repository at this point in the history
Date:   Wed Jul 28 16:12:01 2010 +0200

    0.3.0 version from pickle with rails 3 support
    (taken from http://github.com/szimek/pickle/commit/3b346aefef29d3d628c11d148312c5905264a584)

    With generator in correct directory, and updates to the paths.rb file
  • Loading branch information
ianwhite committed Jul 30, 2010
1 parent fa91277 commit 56ae0ab
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions lib/generators/pickle_generator.rb
@@ -0,0 +1,69 @@
require 'rails/generators'

class PickleGenerator < Rails::Generators::Base
desc "Generates Pickle step files."

# Use the same templates as Rails 2 generator
source_root File.expand_path("../../../rails_generators/pickle/templates", __FILE__)

class_option :paths, :desc => "Generate features/support/paths.rb file.", :type => :boolean
class_option :email, :desc => "Generate features/step_definitions/email_steps.rb file", :type => :boolean

def initialize(args = [], options = {}, config = {})
super

if self.options.paths? && !File.exists?("features/support/paths.rb")
say "features/support/paths.rb not found, is your cucumber up to date?", :red
exit
end
end

def create_directories
empty_directory "features/step_definitions"
empty_directory "features/support"
end

def copy_pickle_steps_file
template "pickle_steps.rb", "features/step_definitions/pickle_steps.rb"
template "pickle.rb", "features/support/pickle.rb"
end

def copy_paths_file
return unless options.paths?

current_paths = File.read("features/support/paths.rb")
unless current_paths.include?('#{capture_model}')
if current_paths =~ /^(.*)(\n\s+else\n\s+raise "Can't find.*".*$)/m
@current_paths_header = $1
@current_paths_footer = $2
end
template "paths.rb", "features/support/paths.rb"
end
end

def copy_email_steps_file
return unless options.email?
template "email_steps.rb", "features/step_definitions/email_steps.rb"
template "email.rb", "features/support/email.rb"
end


private

# Compatibility methods for Rails 2 templates
def pickle_path
options.paths?
end

def pickle_email
options.email?
end

def current_paths_header
@current_paths_header
end

def current_paths_footer
@current_paths_footer
end
end

0 comments on commit 56ae0ab

Please sign in to comment.