Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Author: H.J. Blok <hj.blok@gmail.com>
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
Showing
1 changed file
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |