Commit e5aa3a049c96a3419ece258953547d60114539f8

Authored by Dan Croak
1 parent 2d363e85

updating coulda

vendor/plugins/coulda/features/feature_generator.feature
... ... @@ -8,7 +8,7 @@ Feature: Rails controller generator
8 8 And the coulda plugin is installed
9 9 When I generate a "new" feature for "Posts"
10 10 Then a "posts" feature for the "create" scenario should be generated
11   - And a "posts" step definition should be generated
  11 + And a "create posts" step definition should be generated
12 12 And a new post page path should be generated
13 13  
14 14 Scenario: Feature generator for create action same as new
... ... @@ -16,6 +16,22 @@ Feature: Rails controller generator
16 16 And the coulda plugin is installed
17 17 When I generate a "create" feature for "Posts"
18 18 Then a "posts" feature for the "create" scenario should be generated
19   - And a "posts" step definition should be generated
  19 + And a "create posts" step definition should be generated
20 20 And a new post page path should be generated
21 21  
  22 + Scenario: Feature generator for edit action
  23 + Given a Rails app with Cucumber
  24 + And the coulda plugin is installed
  25 + When I generate a "edit" feature for "Posts"
  26 + Then a "posts" feature for the "edit" scenario should be generated
  27 + And a "update posts" step definition should be generated
  28 + And a edit post page path should be generated
  29 +
  30 + Scenario: Feature generator for update action same as edit
  31 + Given a Rails app with Cucumber
  32 + And the coulda plugin is installed
  33 + When I generate a "update" feature for "Posts"
  34 + Then a "posts" feature for the "update" scenario should be generated
  35 + And a "update posts" step definition should be generated
  36 + And a edit post page path should be generated
  37 +
... ...
vendor/plugins/coulda/features/step_definitions/cucumber_steps.rb
... ... @@ -19,10 +19,17 @@ Then /^a "posts" feature for the "([^\"]*)" scenario should be generated$/ do |a
19 19 " When I create a post named \"A new post\"\n" <<
20 20 " Then I should see \"A new post\""
21 21 end
  22 + elsif %w(edit update).include?(action)
  23 + assert_generated_file("features/posts.feature") do
  24 + " Scenario: Update a post\n" <<
  25 + " Given I am on the edit \"An existing post\" post page\n" <<
  26 + " When I update the post\n" <<
  27 + " Then I should see \"Post updated\""
  28 + end
22 29 end
23 30 end
24 31  
25   -Then /^a "posts" step definition should be generated$/ do
  32 +Then /^a "create posts" step definition should be generated$/ do
26 33 assert_generated_file("features/step_definitions/posts_steps.rb") do
27 34 "When /^I create a post named \"([^\\\"]*)\"$/ do |name|\n" <<
28 35 " fills_in :name, :with => name\n" <<
... ... @@ -38,3 +45,20 @@ Then /^a new post page path should be generated$/ do
38 45 end
39 46 end
40 47  
  48 +Then /^a "update posts" step definition should be generated$/ do
  49 + assert_generated_file("features/step_definitions/posts_steps.rb") do
  50 + "When /^I update a post named \"([^\\\"]*)\"$/ do |name|\n" <<
  51 + " fills_in :name, :with => name\n" <<
  52 + " click_button 'Update'\n"
  53 + "end"
  54 + end
  55 +end
  56 +
  57 +Then /^a edit post page path should be generated$/ do
  58 + assert_generated_file("features/support/paths.rb") do
  59 + " when /the edit \"([^\\\"]*)\" post page/i do |name|\n" <<
  60 + " post = Post.find_by_name(name)\n"
  61 + " edit_post_path(post)"
  62 + end
  63 +end
  64 +
... ...
vendor/plugins/coulda/generators/feature/feature_generator.rb
... ... @@ -22,6 +22,10 @@ class FeatureGenerator &lt; Rails::Generator::NamedBase
22 22 if %w(new create).any? { |action| actions.include?(action) }
23 23 " when /the new #{resource} page/i\n" <<
24 24 " new_#{resource}_path\n"
  25 + elsif %w(edit update).any? { |action| actions.include?(action) }
  26 + " when /the edit \"([^\\\"]*)\" #{resource} page/i do |name|\n" <<
  27 + " post = #{resource_class}.find_by_name(name)\n"
  28 + " edit_#{resource}_path(#{resource})"
25 29 end
26 30 end
27 31 end
... ...
vendor/plugins/coulda/generators/feature/templates/feature.feature
... ... @@ -3,4 +3,9 @@
3 3 Given I am on the new <%= resource %> page
4 4 When I create a <%= resource %> named "A new <%= resource %>"
5 5 Then I should see "A new <%= resource %>"
  6 +<% elsif %w(edit update).any? { |action| actions.include?(action) } -%>
  7 + Scenario: Update a <%= resource %>
  8 + Given I am on the edit "An existing <%= resource %>" <%= resource %> page
  9 + When I update the <%= resource %>
  10 + Then I should see "<%= resource_class %> updated"
6 11 <% end -%>
... ...
vendor/plugins/coulda/generators/feature/templates/step_definition.rb
  1 +<% if %w(new create).any? { |action| actions.include?(action) } -%>
1 2 When /^I create a <%= resource %> named "([^\"]*)"$/ do |name|
2 3 fills_in :name, :with => name
3 4 click_button 'Create'
4 5 end
  6 +<% elsif %w(edit update).any? { |action| actions.include?(action) } -%>
  7 +When /^I update a post named "([^\"]*)"$/ do |name|
  8 + fills_in :name, :with => name
  9 + click_button 'Update'
  10 +end
  11 +<% end -%>
  12 +
... ...
vendor/plugins/coulda/generators/support/insert_commands.rb
1   -# Mostly pinched from http://github.com/ryanb/nifty-generators/tree/master
  1 +# Pinched some from http://github.com/ryanb/nifty-generators
2 2  
3 3 Rails::Generator::Commands::Base.class_eval do
4 4 def file_contains?(relative_destination, line)
... ...