Skip to content

Commit

Permalink
* script/generate pickle path[s] now amends the features/support/pat…
Browse files Browse the repository at this point in the history
…hs.rb file

    instead of creating pge_to_path and path_steps.

  * pickle_email_steps is renamed email_steps
  • Loading branch information
ianwhite committed Jan 27, 2009
1 parent 673f99f commit 62c60b5
Show file tree
Hide file tree
Showing 16 changed files with 118 additions and 96 deletions.
8 changes: 8 additions & 0 deletions History.txt
Original file line number Original file line Diff line number Diff line change
@@ -1,3 +1,11 @@
== 0,1,7

* 2 API changes
* script/generate pickle path[s] now amends the features/support/paths.rb file
instead of creating pge_to_path and path_steps.

* pickle_email_steps is renamed email_steps

== 0.1.6 == 0.1.6


* 1 API change * 1 API change
Expand Down
8 changes: 4 additions & 4 deletions README.rdoc
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ Install pickle either as a rails plugin, or a gem


(you'd better install cucumber) (you'd better install cucumber)


script/generate pickle [path] [email] script/generate pickle [paths] [email]


Now have a look at <tt>features/step_definitions/pickle_steps.rb</tt> Now have a look at <tt>features/step_definitions/pickle_steps.rb</tt>


If you want path steps and email steps then just add 'path' and/or 'email'. The steps will be If you want path steps and email steps then just add 'paths' and/or 'email'. The code/steps will be
written to <tt>features/step_definitions/pickle_path_steps.rb</tt> and written to <tt>features/env/paths.rb</tt> and
<tt>features/step_definitions/pickle_email_steps.rb</tt> respectively. <tt>features/step_definitions/email_steps.rb</tt> respectively.


=== Using with plain ole Active Record === Using with plain ole Active Record


Expand Down
18 changes: 11 additions & 7 deletions features/generator/generators.feature
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ Feature: allow pickle to generate steps
And the file features/support/env.rb should match /require 'pickle\/world'/ And the file features/support/env.rb should match /require 'pickle\/world'/


More Examples: More Examples:
| WHEN I RUN | THE FILE SHOULD EXIST | AND THE FILE | SHOULD MATCH | | WHEN I RUN | THE FILE SHOULD EXIST | AND THE FILE | SHOULD MATCH |
| script/generate pickle | features/step_definitions/pickle_steps.rb | features/support/env.rb | Example of configuring pickle:| | script/generate pickle | features/step_definitions/pickle_steps.rb | features/support/env.rb | Example of configuring pickle:|
| script/generate pickle path | features/step_definitions/pickle_path_steps.rb | features/support/env.rb | require 'pickle\/path\/world' | | script/generate pickle email| features/step_definitions/email_steps.rb | features/support/env.rb | require 'pickle\/email\/world'|
| script/generate pickle email| features/step_definitions/pickle_email_steps.rb | features/support/env.rb | require 'pickle\/email\/world' |


Scenario: script/generate pickle path on fresh cuc install
Given cucumber has been freshly generated
When I run "script/generate pickle path"
Then the file features/support/env.rb should match /require 'pickle\/world'/
And the file features/support/paths.rb should match /added by script/generate pickle path/

Scenario: script/generate pickle, when env.rb has already requires pickle Scenario: script/generate pickle, when env.rb has already requires pickle
Given cucumber has been freshly generated Given cucumber has been freshly generated
And env.rb already requires pickle/world And env.rb already requires pickle/world
Expand All @@ -34,13 +39,12 @@ Feature: allow pickle to generate steps
Scenario: script/generate pickle page email Scenario: script/generate pickle page email
Given cucumber has been freshly generated Given cucumber has been freshly generated
When I run "script/generate pickle path email" When I run "script/generate pickle path email"
Then the file features/step_definitions/pickle_email_steps.rb should exist Then the file features/step_definitions/email_steps.rb should exist
And the file features/step_definitions/pickle_path_steps.rb should exist
And the file features/step_definitions/pickle_steps.rb should exist And the file features/step_definitions/pickle_steps.rb should exist
And the file features/support/env.rb should match /require 'pickle\/world'/ And the file features/support/env.rb should match /require 'pickle\/world'/
And the file features/support/env.rb should match /require 'pickle\/path\/world'/ And the file features/support/env.rb should match /require 'pickle\/path\/world'/
And the file features/support/env.rb should match /require 'pickle\/email\/world'/ And the file features/support/env.rb should match /require 'pickle\/email\/world'/

And the file features/support/paths.rb should match /added by script/generate pickle path/






Expand Down
4 changes: 3 additions & 1 deletion features/path/named_route_page.feature
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ Feature: I can visit a page by named route


Scenario: visit the new spoons page Scenario: visit the new spoons page
When I go to the new spoon page When I go to the new spoon page
Then I should be at /spoons/new Then I should be at the new spoon page
And the new spoon page should match route /spoons/new

8 changes: 0 additions & 8 deletions features/path/path.feature

This file was deleted.

7 changes: 0 additions & 7 deletions features/step_definitions/email_steps.rb

This file was deleted.

1 change: 1 addition & 0 deletions features/step_definitions/email_steps.rb
7 changes: 7 additions & 0 deletions features/step_definitions/extra_email_steps.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,7 @@
Given(/^an email "(.*?)" with body: "(.*?)" is delivered to (.+?)$/) do |subject, body, to|
Notifier.deliver_email(to, subject, body)
end

Given(/^#{capture_model}'s email is delivered$/) do |model|
Notifier.deliver_user_email(model(model))
end
12 changes: 10 additions & 2 deletions features/step_definitions/path_steps.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,12 @@
Then(/^(.+?) page should match route \/(.+?)$/) do |page, route| Then(/^(.+?) should match route \/(.+?)$/) do |page, route|
regexp = route.gsub(/:(\w*?)id/,'\d+') regexp = route.gsub(/:(\w*?)id/,'\d+')
page_to_path(page).should =~ /#{regexp}/ path_to(page).should =~ /#{regexp}/
end

When(/^I go to (.+)$/) do |page|
visit path_to(page)
end

Then(/^I should be at (.+)$/) do |page|
request.path.should =~ /#{path_to(page)}/
end end
1 change: 0 additions & 1 deletion features/step_definitions/pickle_email_steps.rb

This file was deleted.

1 change: 0 additions & 1 deletion features/step_definitions/pickle_path_steps.rb

This file was deleted.

31 changes: 31 additions & 0 deletions features/support/paths.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,31 @@
def path_to(page_name)
case page_name

when /the homepage/i
root_path

# Add more page name => path mappings here

# added by script/generate pickle path

when /^#{capture_model}'s page$/ # eg. the forum's page
pickle_path $1

when /^#{capture_model}'s #{capture_model}'s page$/ # eg. the forum's post's page
pickle_path $1, $2

when /^#{capture_model}'s #{capture_model}'s (.+?) page$/ # eg. the forum's post's comments page
pickle_path $1, $2, :extra => $3 # or the forum's post's edit page

when /^#{capture_model}'s (.+?) page$/ # eg. the forum's posts page
pickle_path $1, :extra => $2 # or the forum's edit page

when /^the (.+?) page$/ # translate to named route
send "#{$1.downcase.gsub(' ','_')}_path"

# end added by pickle path

else
raise "Can't find mapping from \"#{page_name}\" to a path."
end
end
17 changes: 13 additions & 4 deletions rails_generators/pickle/pickle_generator.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,9 +1,11 @@
class PickleGenerator < Rails::Generator::Base class PickleGenerator < Rails::Generator::Base
def initialize(args, options) def initialize(args, options)
super(args, options) super(args, options)
@generate_path_steps = args.include?('page') || args.include?('path')
@generate_email_steps = args.include?('email')
File.exists?('features/support/env.rb') or raise "features/support/env.rb not found, try running script/generate cucumber" File.exists?('features/support/env.rb') or raise "features/support/env.rb not found, try running script/generate cucumber"
@generate_email_steps = args.include?('email')
if @generate_path_steps = args.include?('path') || args.include?('paths')
File.exists?('features/support/paths.rb') or raise "features/support/paths.rb not found, is your cucumber up to date?"
end
end end


def manifest def manifest
Expand All @@ -15,12 +17,19 @@ def manifest


if @generate_path_steps if @generate_path_steps
env_assigns[:pickle_path] = true unless current_env.include?("require 'pickle/path/world'") env_assigns[:pickle_path] = true unless current_env.include?("require 'pickle/path/world'")
m.template 'pickle_path_steps.rb', File.join('features/step_definitions', "pickle_path_steps.rb") current_paths = File.read('features/support/paths.rb')
unless current_paths.include?('#{capture_model}')
if current_paths =~ /^(.*)(\n\s+else\n\s+raise ".*"\n\s+end\nend\s*)$/m
env_assigns[:current_paths_header] = $1
env_assigns[:current_paths_footer] = $2
m.template 'paths.rb', File.join('features/support', "paths.rb"), :assigns => env_assigns, :collision => :force
end
end
end end


if @generate_email_steps if @generate_email_steps
env_assigns[:pickle_email] = true unless current_env.include?("require 'pickle/email/world'") env_assigns[:pickle_email] = true unless current_env.include?("require 'pickle/email/world'")
m.template 'pickle_email_steps.rb', File.join('features/step_definitions', "pickle_email_steps.rb") m.template 'email_steps.rb', File.join('features/step_definitions', "email_steps.rb")
end end


env_assigns[:pickle] = true unless current_env.include?("require 'pickle/world'") env_assigns[:pickle] = true unless current_env.include?("require 'pickle/world'")
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
email(email_ref).body.should_not =~ /#{text}/ email(email_ref).body.should_not =~ /#{text}/
end end


Then(/^#{capture_email} should link to (.+) page$/) do |email_ref, page| Then(/^#{capture_email} should link to (.+)$/) do |email_ref, page|
email(email_ref).body.should =~ /#{page_to_path(page)}/ email(email_ref).body.should =~ /#{path_to(page)}/
end end


Then(/^show me the emails?$/) do Then(/^show me the emails?$/) do
Expand Down
14 changes: 8 additions & 6 deletions rails_generators/pickle/templates/env.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,12 +1,14 @@
<%= current_env %> <%= current_env -%>
<% if pickle %>require 'pickle/world'<% end %> <%- if pickle -%>
<% if pickle_path %>require 'pickle/path/world'<% end %> require 'pickle/world'
<% if pickle_email %>require 'pickle/email/world'<% end %>
<% if pickle %>
# Example of configuring pickle: # Example of configuring pickle:
# #
# Pickle.configure do |config| # Pickle.configure do |config|
# config.adaptors = [:machinist] # config.adaptors = [:machinist]
# config.map 'I', 'myself', 'me', 'my', :to => 'user: "me"' # config.map 'I', 'myself', 'me', 'my', :to => 'user: "me"'
# end # end
<% end -%> <%- end -%>
<%- if pickle_path -%>require 'pickle/path/world'
<%- end -%>
<%- if pickle_email -%>require 'pickle/email/world'
<%- end -%>
20 changes: 20 additions & 0 deletions rails_generators/pickle/templates/paths.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,20 @@
<%= current_paths_header %>
# added by script/generate pickle path
when /^#{capture_model}'s page$/ # eg. the forum's page
pickle_path $1
when /^#{capture_model}'s #{capture_model}'s page$/ # eg. the forum's post's page
pickle_path $1, $2
when /^#{capture_model}'s #{capture_model}'s (.+?) page$/ # eg. the forum's post's comments page
pickle_path $1, $2, :extra => $3 # or the forum's post's edit page

when /^#{capture_model}'s (.+?) page$/ # eg. the forum's posts page
pickle_path $1, :extra => $2 # or the forum's edit page

when /^the (.+?) page$/ # translate to named route
send "#{$1.downcase.gsub(' ','_')}_path"

# end added by pickle path
<%= current_paths_footer %>
53 changes: 0 additions & 53 deletions rails_generators/pickle/templates/pickle_path_steps.rb

This file was deleted.

0 comments on commit 62c60b5

Please sign in to comment.