Commit 20564272be05e14bb940933977ca7166606abd58

Authored by Dan Croak
1 parent 8e8633cd

upgrading coulda

vendor/plugins/coulda/features/controller_generator.feature
... ... @@ -27,6 +27,14 @@ Feature: Rails controller generator
27 27 And a "create" controller action for "posts" should be generated
28 28 And only a "create" action for RESTful "posts" route should be generated
29 29  
  30 + Scenario: Controller generator for create action when Cucumber is installed
  31 + Given a Rails app with Cucumber
  32 + And the coulda plugin is installed
  33 + When I generate a "Posts" controller with "create" action
  34 + Then a standard "create" functional test for "posts" should be generated
  35 + And a "create" controller action for "posts" should be generated
  36 + And only a "create" action for RESTful "posts" route should be generated
  37 +
30 38 Scenario: Controller generator for show action
31 39 Given a Rails app
32 40 And the coulda plugin is installed
... ...
vendor/plugins/coulda/features/step_definitions/controller_steps.rb
... ... @@ -35,7 +35,6 @@ Then /^a standard "create" functional test for "posts" should be generated$/ do
35 35 " setup do\n" <<
36 36 " post :create, :post => Factory.attributes_for(:post)\n" <<
37 37 " end\n\n" <<
38   - " should_create :post\n" <<
39 38 " should_set_the_flash_to /created/i\n" <<
40 39 " should_redirect_to('posts index') { posts_path }\n" <<
41 40 " end"
... ...
vendor/plugins/coulda/features/step_definitions/cucumber_steps.rb 0 → 100644
... ... @@ -0,0 +1,21 @@
  1 +Given /^a Rails app with Cucumber$/ do
  2 + system "rails rails_root"
  3 + @rails_root = File.join(File.dirname(__FILE__), "..", "..", "rails_root")
  4 + require 'cucumber'
  5 +end
  6 +
  7 +Then /^a Cucumber "([^\"]*)" functional test for "([^\"]*)" should be generated$/ do |arg1, arg2|
  8 + pending
  9 +end
  10 +
  11 +Then /^a standard "posts" feature for the "new" scenario should be generated$/ do
  12 + assert_generated_file("features/posts.feature") do |body|
  13 + expected = " Scenario: Create a new 'post'\n" <<
  14 + " Given I am on the new post page\n" <<
  15 + " When I create a 'post' named 'A new post'\n" <<
  16 + " Then I should see 'A new post'"
  17 + assert body.include?(expected),
  18 + "expected #{expected} but was #{body.inspect}"
  19 + end
  20 +end
  21 +
... ...
vendor/plugins/coulda/features/step_definitions/view_steps.rb
1   -Then /^an empty "(.*)" view for "(.*)" should be generated$/ do |action, controller|
2   - assert_generated_views_for(controller, action)
  1 +When /^I generate a "([^\"]*)" view for "([^\"]*)"$/ do |view, resource|
  2 + system "cd #{@rails_root} && " <<
  3 + "script/generate view #{resource} #{view} && " <<
  4 + "cd .."
  5 +end
  6 +
  7 +When /^a standard "new" view for "posts" should be generated$/ do
  8 + assert_generated_file("app/views/posts/new.html.erb") do |body|
  9 + expected = "<h1>New post</h1>\n\n" <<
  10 + "<% form_for(@post) do |form| %>\n" <<
  11 + " <%= form.error_messages %>\n" <<
  12 + " <%= form.submit 'Create', :disable_with => 'Please wait...' %>\n" <<
  13 + "<% end %>"
  14 + assert body.include?(expected),
  15 + "expected #{expected} but was #{body.inspect}"
  16 + end
3 17 end
4 18  
... ...
vendor/plugins/coulda/features/view_generator.feature 0 → 100644
... ... @@ -0,0 +1,12 @@
  1 +Feature: Rails controller generator
  2 + In order to better do Test-Driven Development with Rails
  3 + As a user
  4 + I want to generate Shoulda & Factory Girl tests for only RESTful actions I need.
  5 +
  6 + Scenario: View generator for new action when Cucumber is installed
  7 + Given a Rails app with Cucumber
  8 + And the coulda plugin is installed
  9 + When I generate a "new" view for "Posts"
  10 + Then a standard "new" view for "posts" should be generated
  11 + And a standard "posts" feature for the "new" scenario should be generated
  12 +
... ...
vendor/plugins/coulda/generators/controller/templates/functional_test.rb
... ... @@ -30,7 +30,6 @@ class &lt;%= class_name %&gt;ControllerTest &lt; ActionController::TestCase
30 30 post :create, :<%= resource %> => Factory.attributes_for(:<%= resource %>)
31 31 end
32 32  
33   - should_create :<%= resource %>
34 33 should_set_the_flash_to /created/i
35 34 should_redirect_to('<%= resources %> index') { <%= resources %>_path }
36 35 end
... ...
vendor/plugins/coulda/generators/view/templates/feature.feature 0 → 100644
... ... @@ -0,0 +1,10 @@
  1 +<% resource = file_name.singularize -%>
  2 +<% resources = file_name.pluralize -%>
  3 +<% resource_class = class_name.singularize -%>
  4 +
  5 +<% if %w(new create).any? { |action| actions.include?(action) } -%>
  6 + Scenario: Create a new '<%= resource %>'
  7 + Given I am on the new <%= resource %> page
  8 + When I create a '<%= resource %>' named 'A new <%= resource %>'
  9 + Then I should see 'A new <%= resource %>'
  10 +<% end -%>
... ...
vendor/plugins/coulda/generators/view/templates/view_new.html.erb
1   -<h1>New <%= singular_name %></h1>
  1 +<% resource = file_name.singularize -%>
  2 +<h1>New <%= resource %></h1>
2 3  
3   -<%% form_for(@<%= singular_name %>) do |form| %>
  4 +<%% form_for(@<%= resource %>) do |form| %>
4 5 <%%= form.error_messages %>
5   - <%%= form.submit "Create", :disable_with => "Please wait..." %>
  6 + <%%= form.submit 'Create', :disable_with => 'Please wait...' %>
6 7 <%% end %>
... ...
vendor/plugins/coulda/generators/view/templates/view_show.html.erb 0 → 100644
... ... @@ -0,0 +1,4 @@
  1 +<h1><%= singular_name %></h1>
  2 +
  3 +<%%= link_to 'Edit', edit_<%= singular_name %>_path(@<%= singular_name %>) %>
  4 +
... ...
vendor/plugins/coulda/generators/view/view_generator.rb
... ... @@ -2,12 +2,14 @@ class ViewGenerator &lt; Rails::Generator::NamedBase
2 2 def manifest
3 3 record do |m|
4 4 m.directory File.join('app/views', class_path, file_name)
  5 + m.directory 'features'
5 6  
6   - # View template for specified action.
7 7 if actions.include?("new")
8 8 path = File.join('app/views', class_path, file_name, "new.html.erb")
9   - m.template 'view_new.html.erb', path,
10   - :assigns => { :action => action, :path => path }
  9 + m.template 'view_new.html.erb', path
  10 +
  11 + path = File.join('features', "#{file_name.pluralize}.feature")
  12 + m.template 'feature.feature', path
11 13 end
12 14 end
13 15 end
... ...