Permalink
Browse files

* script/generate pickle path[s] now amends the features/support/pat…

…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 62c60b5191ebcb8f2511174fa3eab1cc0d370749
View
@@ -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
* 1 API change
View
@@ -24,13 +24,13 @@ Install pickle either as a rails plugin, or a gem
(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>
-If you want path steps and email steps then just add 'path' and/or 'email'. The steps will be
-written to <tt>features/step_definitions/pickle_path_steps.rb</tt> and
-<tt>features/step_definitions/pickle_email_steps.rb</tt> respectively.
+If you want path steps and email steps then just add 'paths' and/or 'email'. The code/steps will be
+written to <tt>features/env/paths.rb</tt> and
+<tt>features/step_definitions/email_steps.rb</tt> respectively.
=== Using with plain ole Active Record
@@ -14,11 +14,16 @@ Feature: allow pickle to generate steps
And the file features/support/env.rb should match /require 'pickle\/world'/
More Examples:
- | 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 path | features/step_definitions/pickle_path_steps.rb | features/support/env.rb | require 'pickle\/path\/world' |
- | script/generate pickle email| features/step_definitions/pickle_email_steps.rb | features/support/env.rb | require 'pickle\/email\/world' |
+ | 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 email| features/step_definitions/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
Given cucumber has been freshly generated
And env.rb already requires pickle/world
@@ -34,13 +39,12 @@ Feature: allow pickle to generate steps
Scenario: script/generate pickle page email
Given cucumber has been freshly generated
When I run "script/generate pickle path email"
- Then the file features/step_definitions/pickle_email_steps.rb should exist
- And the file features/step_definitions/pickle_path_steps.rb should exist
+ Then the file features/step_definitions/email_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\/path\/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/
@@ -5,4 +5,6 @@ Feature: I can visit a page by named route
Scenario: visit the new spoons 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
+
@@ -1,8 +0,0 @@
-Feature: I can visit a path, and know when I'm at a path
- In order to nav in my featuers
- As a feature writer
- I want to be able visit paths, and test that I'm at them
-
- Scenario: visit a path
- When I go to /spoons/new
- Then I should be at /spoons/new
@@ -1,7 +0,0 @@
-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
@@ -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
@@ -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+')
- 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
View
@@ -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
@@ -1,9 +1,11 @@
class PickleGenerator < Rails::Generator::Base
def initialize(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"
+ @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
def manifest
@@ -15,12 +17,19 @@ def manifest
if @generate_path_steps
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
if @generate_email_steps
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
env_assigns[:pickle] = true unless current_env.include?("require 'pickle/world'")
@@ -41,8 +41,8 @@
email(email_ref).body.should_not =~ /#{text}/
end
-Then(/^#{capture_email} should link to (.+) page$/) do |email_ref, page|
- email(email_ref).body.should =~ /#{page_to_path(page)}/
+Then(/^#{capture_email} should link to (.+)$/) do |email_ref, page|
+ email(email_ref).body.should =~ /#{path_to(page)}/
end
Then(/^show me the emails?$/) do
@@ -1,12 +1,14 @@
-<%= current_env %>
-<% if pickle %>require 'pickle/world'<% end %>
-<% if pickle_path %>require 'pickle/path/world'<% end %>
-<% if pickle_email %>require 'pickle/email/world'<% end %>
-<% if pickle %>
+<%= current_env -%>
+<%- if pickle -%>
+require 'pickle/world'
# Example of configuring pickle:
#
# Pickle.configure do |config|
# config.adaptors = [:machinist]
# config.map 'I', 'myself', 'me', 'my', :to => 'user: "me"'
# end
-<% end -%>
+<%- end -%>
+<%- if pickle_path -%>require 'pickle/path/world'
+<%- end -%>
+<%- if pickle_email -%>require 'pickle/email/world'
+<%- end -%>
@@ -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 %>
@@ -1,53 +0,0 @@
-# this file generated by script/generate pickle page.
-# You should edit the page_to_path method below for your own app's needs
-
-# When I go to /sessions/new
-When(/^I go to \/(.+?)$/) do |path|
- visit "/#{path}"
-end
-
-# Then I should be at /sessions/new
-Then(/^I should be at \/(.+?)$/) do |path|
- request.path.should =~ /^\/#{path}/
-end
-
-# When I go to the posts's new comment page
-When(/^I go to (.+?) page$/) do |page|
- visit page_to_path(page)
-end
-
-# Then I should be at the posts's new comment page
-Then(/^I should be at (.+?) page$/) do |page|
- request.path.should =~ /^#{page_to_path(page)}/
-end
-
-# passed a string like 'the home', returns a path
-def page_to_path(page)
- case page
- # add your own app-specific mappings, e.g.
- #
- # when 'the home'
- # '/'
- #
- # when /$#{capture_model}'s activation^/
- # activation_by_code_path(created_model($1).activation_code)
-
- when /^#{capture_model}'s$/ # the forum's
- pickle_path $1
-
- when /^#{capture_model}'s #{capture_model}'s$/ # the forum's post's
- pickle_path $1, $2
-
- when /^#{capture_model}'s #{capture_model}'s (.+?)$/ # the forum's post's comments
- pickle_path $1, $2, :extra => $3
-
- when /^#{capture_model}'s (.+?)$/ # the post's comments
- pickle_path $1, :extra => $2
-
- when /^the (.+?)$/ # the new session
- send "#{$1.downcase.gsub(' ','_')}_path"
-
- else
- raise "Could not map '#{page}' page to a path"
- end
-end

0 comments on commit 62c60b5

Please sign in to comment.