Commit e5aa3a049c96a3419ece258953547d60114539f8
1 parent
2d363e85
Exists in
master
and in
1 other branch
updating coulda
Showing
6 changed files
with
61 additions
and
4 deletions
Show diff stats
vendor/plugins/coulda/features/feature_generator.feature
@@ -8,7 +8,7 @@ Feature: Rails controller generator | @@ -8,7 +8,7 @@ Feature: Rails controller generator | ||
8 | And the coulda plugin is installed | 8 | And the coulda plugin is installed |
9 | When I generate a "new" feature for "Posts" | 9 | When I generate a "new" feature for "Posts" |
10 | Then a "posts" feature for the "create" scenario should be generated | 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 | And a new post page path should be generated | 12 | And a new post page path should be generated |
13 | 13 | ||
14 | Scenario: Feature generator for create action same as new | 14 | Scenario: Feature generator for create action same as new |
@@ -16,6 +16,22 @@ Feature: Rails controller generator | @@ -16,6 +16,22 @@ Feature: Rails controller generator | ||
16 | And the coulda plugin is installed | 16 | And the coulda plugin is installed |
17 | When I generate a "create" feature for "Posts" | 17 | When I generate a "create" feature for "Posts" |
18 | Then a "posts" feature for the "create" scenario should be generated | 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 | And a new post page path should be generated | 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,10 +19,17 @@ Then /^a "posts" feature for the "([^\"]*)" scenario should be generated$/ do |a | ||
19 | " When I create a post named \"A new post\"\n" << | 19 | " When I create a post named \"A new post\"\n" << |
20 | " Then I should see \"A new post\"" | 20 | " Then I should see \"A new post\"" |
21 | end | 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 | end | 29 | end |
23 | end | 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 | assert_generated_file("features/step_definitions/posts_steps.rb") do | 33 | assert_generated_file("features/step_definitions/posts_steps.rb") do |
27 | "When /^I create a post named \"([^\\\"]*)\"$/ do |name|\n" << | 34 | "When /^I create a post named \"([^\\\"]*)\"$/ do |name|\n" << |
28 | " fills_in :name, :with => name\n" << | 35 | " fills_in :name, :with => name\n" << |
@@ -38,3 +45,20 @@ Then /^a new post page path should be generated$/ do | @@ -38,3 +45,20 @@ Then /^a new post page path should be generated$/ do | ||
38 | end | 45 | end |
39 | end | 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 < Rails::Generator::NamedBase | @@ -22,6 +22,10 @@ class FeatureGenerator < Rails::Generator::NamedBase | ||
22 | if %w(new create).any? { |action| actions.include?(action) } | 22 | if %w(new create).any? { |action| actions.include?(action) } |
23 | " when /the new #{resource} page/i\n" << | 23 | " when /the new #{resource} page/i\n" << |
24 | " new_#{resource}_path\n" | 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 | end | 29 | end |
26 | end | 30 | end |
27 | end | 31 | end |
vendor/plugins/coulda/generators/feature/templates/feature.feature
@@ -3,4 +3,9 @@ | @@ -3,4 +3,9 @@ | ||
3 | Given I am on the new <%= resource %> page | 3 | Given I am on the new <%= resource %> page |
4 | When I create a <%= resource %> named "A new <%= resource %>" | 4 | When I create a <%= resource %> named "A new <%= resource %>" |
5 | Then I should see "A new <%= resource %>" | 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 | <% end -%> | 11 | <% end -%> |
vendor/plugins/coulda/generators/feature/templates/step_definition.rb
1 | +<% if %w(new create).any? { |action| actions.include?(action) } -%> | ||
1 | When /^I create a <%= resource %> named "([^\"]*)"$/ do |name| | 2 | When /^I create a <%= resource %> named "([^\"]*)"$/ do |name| |
2 | fills_in :name, :with => name | 3 | fills_in :name, :with => name |
3 | click_button 'Create' | 4 | click_button 'Create' |
4 | end | 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 | Rails::Generator::Commands::Base.class_eval do | 3 | Rails::Generator::Commands::Base.class_eval do |
4 | def file_contains?(relative_destination, line) | 4 | def file_contains?(relative_destination, line) |