diff --git a/vendor/plugins/coulda/README.textile b/vendor/plugins/coulda/README.textile index 882301c..780ddb5 100644 --- a/vendor/plugins/coulda/README.textile +++ b/vendor/plugins/coulda/README.textile @@ -1,16 +1,58 @@ h1. Coulda generators -A plugin that overrides Rails' model, controller, & helper generators. It also adds a view generator. It uses Shoulda & Factory Girl for tests. +A Rails plugin for feature, view, controller, model, & helper generators. It is meant to be used as part of an "Outside-In" Test-Driven Development cycle. h2. Requirements +* "Cucumber":http://github.com/aslakhellesoy/cucumber * "Shoulda":http://github.com/thoughtbot/shoulda * "Factory Girl":http://github.com/thoughtbot/factory_girl +* "Mocha":http://github.com/jferris/mocha h2. Installation $ script/plugin install git://github.com/dancroak/coulda.git +h2. Feature generator + + $ script/generate feature Posts new create + +generates... + +
Scenario: Create a new post
+ Given I am on the new post page
+ When I create a 'post' named 'A new post'
+ Then I should see 'A new post'
+
+Now run it:
+
+ $ cucumber features/posts.feature
+
+The failure will be:
+
+ undefined method `new_post_path'
+
+To get past this error, we'll create just the route we need:
+
+ map.resources :posts, :only => [:new]
+
+Running the test again, we have a new failure:
+
+ uninitialized constant PostsController
+
+h2. Controller test generator
+
+We've reached a point in our Outside-In cycle where we want to spiral down into a tighter feedback loop to unit test the non-existant controller.
+
+ $ script/generate controller_test Posts new create
+
+h2. Controller generator
+
+ $ script/generate controller Posts new create
+
+generates...
+
+
h2. Model generator
$ script/generate model User
@@ -20,14 +62,6 @@ h2. Model generator
* migration
* model
-h2. Controller generator
-
- $ script/generate controller Users new
-
-* functional test (Shoulda & Factory Girl), only test RESTful new action
-* controller, only RESTful new action
-* no helper file
-
h2. Helper generator
$ script/generate helper Navigation
@@ -39,16 +73,11 @@ h2. View generator
$ script/generate view Posts new
-* We're not sure we like this one yet. Let us know what you think.
-
h2. Model generator: belongs_to
$ script/generate model post user:belongs_to
-* "add_index" in the migration
-* "belongs_to" in the model
-* "should_belong_to" in unit test
-* association in the factory
+generates...
class CreatePosts < ActiveRecord::Migration
def self.up
diff --git a/vendor/plugins/coulda/features/controller_generator.feature b/vendor/plugins/coulda/features/controller_generator.feature
index 22575b9..e4986ac 100644
--- a/vendor/plugins/coulda/features/controller_generator.feature
+++ b/vendor/plugins/coulda/features/controller_generator.feature
@@ -9,7 +9,6 @@ Feature: Rails controller generator
When I generate a "Posts" controller with "index" action
Then a standard "index" functional test for "posts" should be generated
And an empty "index" controller action for "posts" should be generated
- And only a "index" action for RESTful "posts" route should be generated
Scenario: Controller generator for new action
Given a Rails app
@@ -17,7 +16,6 @@ Feature: Rails controller generator
When I generate a "Posts" controller with "new" action
Then a standard "new" functional test for "posts" should be generated
And a "new" controller action for "posts" should be generated
- And only a "new" action for RESTful "posts" route should be generated
Scenario: Controller generator for create action
Given a Rails app
@@ -25,7 +23,6 @@ Feature: Rails controller generator
When I generate a "Posts" controller with "create" action
Then a standard "create" functional test for "posts" should be generated
And a "create" controller action for "posts" should be generated
- And only a "create" action for RESTful "posts" route should be generated
Scenario: Controller generator for create action when Cucumber is installed
Given a Rails app with Cucumber
@@ -33,7 +30,6 @@ Feature: Rails controller generator
When I generate a "Posts" controller with "create" action
Then a standard "create" functional test for "posts" should be generated
And a "create" controller action for "posts" should be generated
- And only a "create" action for RESTful "posts" route should be generated
Scenario: Controller generator for show action
Given a Rails app
@@ -41,7 +37,6 @@ Feature: Rails controller generator
When I generate a "Posts" controller with "show" action
Then a standard "show" functional test for "posts" should be generated
And a "show" controller action for "posts" should be generated
- And only a "show" action for RESTful "posts" route should be generated
Scenario: Controller generator for edit action
Given a Rails app
@@ -49,7 +44,6 @@ Feature: Rails controller generator
When I generate a "Posts" controller with "edit" action
Then a standard "edit" functional test for "posts" should be generated
And a "edit" controller action for "posts" should be generated
- And only a "edit" action for RESTful "posts" route should be generated
Scenario: Controller generator for update action
Given a Rails app
@@ -57,7 +51,6 @@ Feature: Rails controller generator
When I generate a "Posts" controller with "update" action
Then a standard "update" functional test for "posts" should be generated
And a "update" controller action for "posts" should be generated
- And only a "update" action for RESTful "posts" route should be generated
Scenario: Controller generator for destroy action
Given a Rails app
@@ -65,5 +58,4 @@ Feature: Rails controller generator
When I generate a "Posts" controller with "destroy" action
Then a standard "destroy" functional test for "posts" should be generated
And a "destroy" controller action for "posts" should be generated
- And only a "destroy" action for RESTful "posts" route should be generated
diff --git a/vendor/plugins/coulda/features/feature_generator.feature b/vendor/plugins/coulda/features/feature_generator.feature
new file mode 100644
index 0000000..c6d8b4d
--- /dev/null
+++ b/vendor/plugins/coulda/features/feature_generator.feature
@@ -0,0 +1,21 @@
+Feature: Rails controller generator
+ In order to better do Test-Driven Development with Rails
+ As a user
+ I want to generate Shoulda & Factory Girl tests for only RESTful actions I need.
+
+ Scenario: Feature generator for new action
+ Given a Rails app with Cucumber
+ And the coulda plugin is installed
+ When I generate a "new" feature for "Posts"
+ Then a "posts" feature for the "create" scenario should be generated
+ And a "posts" step definition should be generated
+ And a new post page path should be generated
+
+ Scenario: Feature generator for create action same as new
+ Given a Rails app with Cucumber
+ And the coulda plugin is installed
+ When I generate a "create" feature for "Posts"
+ Then a "posts" feature for the "create" scenario should be generated
+ And a "posts" step definition should be generated
+ And a new post page path should be generated
+
diff --git a/vendor/plugins/coulda/features/step_definitions/controller_steps.rb b/vendor/plugins/coulda/features/step_definitions/controller_steps.rb
index b76a533..d8adfe1 100644
--- a/vendor/plugins/coulda/features/step_definitions/controller_steps.rb
+++ b/vendor/plugins/coulda/features/step_definitions/controller_steps.rb
@@ -5,180 +5,155 @@ When /^I generate a "(.*)" controller with "(.*)" action$/ do |controller, actio
end
Then /^a standard "index" functional test for "posts" should be generated$/ do
- assert_generated_functional_test_for("posts") do |body|
- expected = " context 'GET to index' do\n" <<
- " setup { get :index }\n\n" <<
- " should_render_template :index\n" <<
- " should_respond_with :success\n" <<
- " end"
- assert body.include?(expected),
- "expected #{expected} but was #{body.inspect}"
+ assert_generated_file("test/functional/posts_controller_test.rb") do
+ " context 'GET to index' do\n" <<
+ " setup { get :index }\n\n" <<
+ " should_render_template :index\n" <<
+ " should_respond_with :success\n" <<
+ " end"
+ end
+end
+
+Then /^an empty "index" controller action for "posts" should be generated$/ do
+ assert_generated_file("app/controllers/posts_controller.rb") do
+ " def index\n" <<
+ " end"
end
end
Then /^a standard "new" functional test for "posts" should be generated$/ do
- assert_generated_functional_test_for("posts") do |body|
- expected = " context 'GET to new' do\n" <<
- " setup { get :new }\n\n" <<
- " should_assign_to :post\n" <<
- " should_render_template :new\n" <<
- " should_respond_with :success\n" <<
- " end"
- assert body.include?(expected),
- "expected #{expected} but was #{body.inspect}"
+ assert_generated_file("test/functional/posts_controller_test.rb") do
+ " context 'GET to new' do\n" <<
+ " setup { get :new }\n\n" <<
+ " should_assign_to :post\n" <<
+ " should_render_template :new\n" <<
+ " should_respond_with :success\n" <<
+ " end"
end
end
Then /^a standard "create" functional test for "posts" should be generated$/ do
- assert_generated_functional_test_for("posts") do |body|
- expected = " context 'POST to create with valid parameters' do\n" <<
- " setup do\n" <<
- " post :create, :post => Factory.attributes_for(:post)\n" <<
- " end\n\n" <<
- " should_set_the_flash_to /created/i\n" <<
- " should_redirect_to('posts index') { posts_path }\n" <<
- " end"
- assert body.include?(expected),
- "expected #{expected} but was #{body.inspect}"
+ assert_generated_file("test/functional/posts_controller_test.rb") do
+ " context 'POST to create with valid parameters' do\n" <<
+ " setup do\n" <<
+ " post :create, :post => Factory.attributes_for(:post)\n" <<
+ " end\n\n" <<
+ " should_set_the_flash_to /created/i\n" <<
+ " should_redirect_to('posts index') { posts_path }\n" <<
+ " end"
end
end
Then /^a standard "show" functional test for "posts" should be generated$/ do
- assert_generated_functional_test_for("posts") do |body|
- expected = " context 'GET to show for existing post' do\n" <<
- " setup do\n" <<
- " @post = Factory(:post)\n" <<
- " get :show, :id => @post.to_param\n" <<
- " end\n\n" <<
- " should_assign_to :post, :equals => '@post'\n" <<
- " should_render_template :show\n" <<
- " should_respond_with :success\n" <<
- " end"
- assert body.include?(expected),
- "expected #{expected} but was #{body.inspect}"
+ assert_generated_file("test/functional/posts_controller_test.rb") do
+ " context 'GET to show for existing post' do\n" <<
+ " setup do\n" <<
+ " @post = Factory(:post)\n" <<
+ " get :show, :id => @post.to_param\n" <<
+ " end\n\n" <<
+ " should_assign_to :post, :equals => '@post'\n" <<
+ " should_render_template :show\n" <<
+ " should_respond_with :success\n" <<
+ " end"
end
end
Then /^a standard "edit" functional test for "posts" should be generated$/ do
- assert_generated_functional_test_for("posts") do |body|
- expected = " context 'GET to edit for existing post' do\n" <<
- " setup do\n" <<
- " @post = Factory(:post)\n" <<
- " get :edit, :id => @post.to_param\n" <<
- " end\n\n" <<
- " should_assign_to :post, :equals => '@post'\n" <<
- " should_render_template :edit\n" <<
- " should_respond_with :success\n" <<
- " end"
- assert body.include?(expected),
- "expected #{expected} but was #{body.inspect}"
+ assert_generated_file("test/functional/posts_controller_test.rb") do
+ " context 'GET to edit for existing post' do\n" <<
+ " setup do\n" <<
+ " @post = Factory(:post)\n" <<
+ " get :edit, :id => @post.to_param\n" <<
+ " end\n\n" <<
+ " should_assign_to :post, :equals => '@post'\n" <<
+ " should_render_template :edit\n" <<
+ " should_respond_with :success\n" <<
+ " end"
end
end
Then /^a standard "update" functional test for "posts" should be generated$/ do
- assert_generated_functional_test_for("posts") do |body|
- expected = " context 'PUT to update for existing post' do\n" <<
- " setup do\n" <<
- " @post = Factory(:post)\n" <<
- " put :update, :id => @post.to_param,\n" <<
- " :post => Factory.attributes_for(:post)\n" <<
- " end\n\n" <<
- " should_set_the_flash_to /updated/i\n" <<
- " should_redirect_to('posts index') { posts_path }\n" <<
- " end"
- assert body.include?(expected),
- "expected #{expected} but was #{body.inspect}"
+ assert_generated_file("test/functional/posts_controller_test.rb") do
+ " context 'PUT to update for existing post' do\n" <<
+ " setup do\n" <<
+ " @post = Factory(:post)\n" <<
+ " put :update, :id => @post.to_param,\n" <<
+ " :post => Factory.attributes_for(:post)\n" <<
+ " end\n\n" <<
+ " should_set_the_flash_to /updated/i\n" <<
+ " should_redirect_to('posts index') { posts_path }\n" <<
+ " end"
end
end
Then /^a standard "destroy" functional test for "posts" should be generated$/ do
- assert_generated_functional_test_for("posts") do |body|
- expected = " context 'given a post' do\n" <<
- " setup { @post = Factory(:post) }\n\n" <<
- " context 'DELETE to destroy' do\n" <<
- " setup { delete :destroy, :id => @post.to_param }\n\n" <<
- " should_destroy :post\n" <<
- " should_set_the_flash_to /deleted/i\n" <<
- " should_redirect_to('posts index') { posts_path }\n" <<
- " end\n" <<
- " end"
- assert body.include?(expected),
- "expected #{expected} but was #{body.inspect}"
+ assert_generated_file("test/functional/posts_controller_test.rb") do
+ " context 'given a post' do\n" <<
+ " setup { @post = Factory(:post) }\n\n" <<
+ " context 'DELETE to destroy' do\n" <<
+ " setup { delete :destroy, :id => @post.to_param }\n\n" <<
+ " should_destroy :post\n" <<
+ " should_set_the_flash_to /deleted/i\n" <<
+ " should_redirect_to('posts index') { posts_path }\n" <<
+ " end\n" <<
+ " end"
end
end
Then /^a "new" controller action for "posts" should be generated$/ do
- assert_generated_controller_for("posts") do |body|
- expected = " def new\n" <<
- " @post = Post.new\n" <<
- " end"
- assert body.include?(expected),
- "expected #{expected} but was #{body.inspect}"
+ assert_generated_file("app/controllers/posts_controller.rb") do
+ " def new\n" <<
+ " @post = Post.new\n" <<
+ " end"
end
end
Then /^a "create" controller action for "posts" should be generated$/ do
- assert_generated_controller_for("posts") do |body|
- expected = " def create\n" <<
- " @post = Post.new(params[:post])\n" <<
- " @post.save\n" <<
- " flash[:success] = 'Post created.'\n" <<
- " redirect_to posts_path\n" <<
- " end"
- assert body.include?(expected),
- "expected #{expected} but was #{body.inspect}"
+ assert_generated_file("app/controllers/posts_controller.rb") do
+ " def create\n" <<
+ " @post = Post.new(params[:post])\n" <<
+ " @post.save\n" <<
+ " flash[:success] = 'Post created.'\n" <<
+ " redirect_to posts_path\n" <<
+ " end"
end
end
Then /^a "show" controller action for "posts" should be generated$/ do
- assert_generated_controller_for("posts") do |body|
- expected = " def show\n" <<
- " @post = Post.find(params[:id])\n" <<
- " end"
- assert body.include?(expected),
- "expected #{expected} but was #{body.inspect}"
+ assert_generated_file("app/controllers/posts_controller.rb") do
+ " def show\n" <<
+ " @post = Post.find(params[:id])\n" <<
+ " end"
end
end
Then /^a "edit" controller action for "posts" should be generated$/ do
- assert_generated_controller_for("posts") do |body|
- expected = " def edit\n" <<
- " @post = Post.find(params[:id])\n" <<
- " end"
- assert body.include?(expected),
- "expected #{expected} but was #{body.inspect}"
+ assert_generated_file("app/controllers/posts_controller.rb") do
+ " def edit\n" <<
+ " @post = Post.find(params[:id])\n" <<
+ " end"
end
end
Then /^a "update" controller action for "posts" should be generated$/ do
- assert_generated_controller_for("posts") do |body|
- expected = " def update\n" <<
- " @post = Post.find(params[:id])\n" <<
- " @post.update_attributes(params[:post])\n" <<
- " flash[:success] = 'Post updated.'\n" <<
- " redirect_to posts_path\n" <<
- " end"
- assert body.include?(expected),
- "expected #{expected} but was #{body.inspect}"
+ assert_generated_file("app/controllers/posts_controller.rb") do
+ " def update\n" <<
+ " @post = Post.find(params[:id])\n" <<
+ " @post.update_attributes(params[:post])\n" <<
+ " flash[:success] = 'Post updated.'\n" <<
+ " redirect_to posts_path\n" <<
+ " end"
end
end
Then /^a "destroy" controller action for "posts" should be generated$/ do
- assert_generated_controller_for("posts") do |body|
- expected = " def destroy\n" <<
- " @post = Post.find(params[:id])\n" <<
- " @post.destroy\n" <<
- " flash[:success] = 'Post deleted.'\n" <<
- " redirect_to posts_path\n" <<
- " end"
- assert body.include?(expected),
- "expected #{expected} but was #{body.inspect}"
- end
-end
-
-Then /^an empty "(.*)" controller action for "(.*)" should be generated$/ do |action, controller|
- assert_generated_controller_for(controller) do |body|
- assert_has_empty_method(body, action)
+ assert_generated_file("app/controllers/posts_controller.rb") do
+ " def destroy\n" <<
+ " @post = Post.find(params[:id])\n" <<
+ " @post.destroy\n" <<
+ " flash[:success] = 'Post deleted.'\n" <<
+ " redirect_to posts_path\n" <<
+ " end"
end
end
diff --git a/vendor/plugins/coulda/features/step_definitions/cucumber_steps.rb b/vendor/plugins/coulda/features/step_definitions/cucumber_steps.rb
index 98c80cb..df0e8ba 100644
--- a/vendor/plugins/coulda/features/step_definitions/cucumber_steps.rb
+++ b/vendor/plugins/coulda/features/step_definitions/cucumber_steps.rb
@@ -2,20 +2,39 @@ Given /^a Rails app with Cucumber$/ do
system "rails rails_root"
@rails_root = File.join(File.dirname(__FILE__), "..", "..", "rails_root")
require 'cucumber'
+ system "cd #{@rails_root} && ruby script/generate cucumber"
end
-Then /^a Cucumber "([^\"]*)" functional test for "([^\"]*)" should be generated$/ do |arg1, arg2|
- pending
+When /^I generate a "([^\"]*)" feature for "([^\"]*)"$/ do |feature, resource|
+ system "cd #{@rails_root} && " <<
+ "script/generate feature #{resource} #{feature} && " <<
+ "cd .."
end
-Then /^a standard "posts" feature for the "new" scenario should be generated$/ do
- assert_generated_file("features/posts.feature") do |body|
- expected = " Scenario: Create a new 'post'\n" <<
- " Given I am on the new post page\n" <<
- " When I create a 'post' named 'A new post'\n" <<
- " Then I should see 'A new post'"
- assert body.include?(expected),
- "expected #{expected} but was #{body.inspect}"
+Then /^a "posts" feature for the "([^\"]*)" scenario should be generated$/ do |action|
+ if %w(new create).include?(action)
+ assert_generated_file("features/posts.feature") do
+ " Scenario: Create a new post\n" <<
+ " Given I am on the new post page\n" <<
+ " When I create a post named \"A new post\"\n" <<
+ " Then I should see \"A new post\""
+ end
+ end
+end
+
+Then /^a "posts" step definition should be generated$/ do
+ assert_generated_file("features/step_definitions/posts_steps.rb") do
+ "When /^I create a post named \"([^\\\"]*)\"$/ do |name|\n" <<
+ " fills_in :name, :with => name\n" <<
+ " click_button 'Create'\n"
+ "end"
+ end
+end
+
+Then /^a new post page path should be generated$/ do
+ assert_generated_file("features/support/paths.rb") do
+ " when /the new post page/i\n" <<
+ " new_post_path"
end
end
diff --git a/vendor/plugins/coulda/features/step_definitions/helper_steps.rb b/vendor/plugins/coulda/features/step_definitions/helper_steps.rb
index b7f8bcc..240eaa9 100644
--- a/vendor/plugins/coulda/features/step_definitions/helper_steps.rb
+++ b/vendor/plugins/coulda/features/step_definitions/helper_steps.rb
@@ -5,10 +5,10 @@ When /^I generate a helper named "(.*)"$/ do |name|
end
Then /^a helper should be generated for "(.*)"$/ do |name|
- assert_generated_helper_for(name)
+ assert_generated_file("app/helpers/#{name}_helper.rb")
end
Then /^a helper test should be generated for "(.*)"$/ do |name|
- assert_generated_helper_test_for(name)
+ assert_generated_file("test/unit/helpers/#{name}_helper_test.rb")
end
diff --git a/vendor/plugins/coulda/features/step_definitions/model_steps.rb b/vendor/plugins/coulda/features/step_definitions/model_steps.rb
index 0a280ff..c726d1f 100644
--- a/vendor/plugins/coulda/features/step_definitions/model_steps.rb
+++ b/vendor/plugins/coulda/features/step_definitions/model_steps.rb
@@ -28,26 +28,10 @@ end
# MODEL
-Then /^a model with comments should be generated for "(.*)"$/ do |model|
- model.downcase!
- assert_generated_model_for(model) do |body|
- comments = []
- comments << "# includes: mixed in behavior" <<
- "# properties: attributes, associations" <<
- "# lifecycle: validations, callbacks" <<
- "# class methods: self.method, named_scopes" <<
- "# instance methods" <<
- "# non-public interface: protected helpers"
- comments.each do |comment|
- assert body.include?(comment), body.inspect
- end
- end
-end
-
Then /^the "(.*)" model should have "(.*)" macro$/ do |model, macro|
model.downcase!
- assert_generated_model_for(model) do |body|
- assert body.include?(macro), body.inspect
+ assert_generated_file("app/models/#{model}.rb") do
+ macro
end
end
@@ -55,31 +39,28 @@ end
Then /^a factory should be generated for "(.*)"$/ do |model|
model.downcase!
- assert_generated_factory_for(model) do |body|
- expected = "Factory.define :#{model.downcase} do |#{model.downcase}|\n" <<
- "end\n"
- assert_equal expected, body
+ assert_generated_file("test/factories/#{model}.rb") do
+ "Factory.define :#{model.downcase} do |#{model.downcase}|\n" <<
+ "end\n"
end
end
Then /^a factory for "(.*)" should have an? "(.*)" (.*)$/ do |model, attr_name, attr_type|
model.downcase!
- assert_generated_factory_for(model) do |body|
- expected = "Factory.define :#{model} do |#{model}|\n" <<
- " #{model}.#{attr_name} { '#{attr_type}' }\n" <<
- "end\n"
- assert_equal expected, body
+ assert_generated_file("test/factories/#{model}.rb") do
+ "Factory.define :#{model} do |#{model}|\n" <<
+ " #{model}.#{attr_name} { '#{attr_type}' }\n" <<
+ "end\n"
end
end
Then /^a factory for "(.*)" should have an association to "(.*)"$/ do |model, associated_model|
model.downcase!
associated_model.downcase!
- assert_generated_factory_for(model) do |body|
- expected = "Factory.define :#{model} do |#{model}|\n" <<
- " #{model}.association(:#{associated_model})\n" <<
- "end\n"
- assert_equal expected, body
+ assert_generated_file("test/factories/#{model}.rb") do
+ "Factory.define :#{model} do |#{model}|\n" <<
+ " #{model}.association(:#{associated_model})\n" <<
+ "end\n"
end
end
@@ -87,35 +68,32 @@ end
Then /^a unit test should be generated for "(.*)"$/ do |model|
model.downcase!
- assert_generated_unit_test_for(model) do |body|
- match = "assert_valid Factory.build(:#{model})"
- assert body.include?(match), body.inspect
+ assert_generated_file("test/unit/#{model}_test.rb") do
+ "assert_valid Factory.build(:#{model})"
end
end
Then /^the "(.*)" unit test should have "(.*)" macro$/ do |model, macro|
model.downcase!
- assert_generated_unit_test_for(model) do |body|
- assert body.include?(macro), body.inspect
+ assert_generated_file("test/unit/#{model}_test.rb") do
+ macro
end
end
# MIGRATION
Then /^the "(.*)" table should have db index on "(.*)"$/ do |table, foreign_key|
- assert_generated_migration(table) do |body|
- index = "add_index :#{table}, :#{foreign_key}"
- assert body.include?(index), body.inspect
+ assert_generated_migration(table) do
+ "add_index :#{table}, :#{foreign_key}"
end
end
Then /^the "(.*)" table should have paperclip columns for "(.*)"$/ do |table, attr|
- up = " table.string :#{attr}_file_name\n" <<
- " table.string :#{attr}_content_type\n" <<
- " table.integer :#{attr}_file_size\n" <<
- " table.datetime :#{attr}_updated_at"
- assert_generated_migration(table) do |body|
- assert body.include?(up), body.inspect
+ assert_generated_migration(table) do
+ " table.string :#{attr}_file_name\n" <<
+ " table.string :#{attr}_content_type\n" <<
+ " table.integer :#{attr}_file_size\n" <<
+ " table.datetime :#{attr}_updated_at"
end
end
diff --git a/vendor/plugins/coulda/features/step_definitions/view_steps.rb b/vendor/plugins/coulda/features/step_definitions/view_steps.rb
index 2a47dec..2919643 100644
--- a/vendor/plugins/coulda/features/step_definitions/view_steps.rb
+++ b/vendor/plugins/coulda/features/step_definitions/view_steps.rb
@@ -5,14 +5,12 @@ When /^I generate a "([^\"]*)" view for "([^\"]*)"$/ do |view, resource|
end
When /^a standard "new" view for "posts" should be generated$/ do
- assert_generated_file("app/views/posts/new.html.erb") do |body|
- expected = "New post
\n\n" <<
- "<% form_for(@post) do |form| %>\n" <<
- " <%= form.error_messages %>\n" <<
- " <%= form.submit 'Create', :disable_with => 'Please wait...' %>\n" <<
- "<% end %>"
- assert body.include?(expected),
- "expected #{expected} but was #{body.inspect}"
+ assert_generated_file("app/views/posts/new.html.erb") do
+ "New post
\n\n" <<
+ "<% form_for(@post) do |form| %>\n" <<
+ " <%= form.error_messages %>\n" <<
+ " <%= form.submit 'Create', :disable_with => 'Please wait...' %>\n" <<
+ "<% end %>"
end
end
diff --git a/vendor/plugins/coulda/features/support/env.rb b/vendor/plugins/coulda/features/support/env.rb
index 74581c1..f7bbc24 100644
--- a/vendor/plugins/coulda/features/support/env.rb
+++ b/vendor/plugins/coulda/features/support/env.rb
@@ -2,52 +2,15 @@ require 'test/unit'
module Test::Unit::Assertions
- def assert_generated_controller_for(name)
- assert_generated_file "app/controllers/#{name}_controller.rb" do |body|
- yield body if block_given?
- end
- end
-
- def assert_generated_model_for(name)
- assert_generated_file "app/models/#{name}.rb" do |body|
- yield body if block_given?
- end
- end
-
- def assert_generated_helper_for(name)
- assert_generated_file "app/helpers/#{name}_helper.rb" do |body|
- yield body if block_given?
- end
- end
-
- def assert_generated_factory_for(name)
- assert_generated_file "test/factories/#{name}.rb" do |body|
- yield body if block_given?
- end
- end
-
- def assert_generated_functional_test_for(name)
- assert_generated_file "test/functional/#{name}_controller_test.rb" do |body|
- yield body if block_given?
- end
- end
-
- def assert_generated_unit_test_for(name)
- assert_generated_file "test/unit/#{name}_test.rb" do |body|
- yield body if block_given?
- end
- end
-
- def assert_generated_helper_test_for(name)
- assert_generated_file "test/unit/helpers/#{name}_helper_test.rb" do |body|
- yield body if block_given?
- end
- end
-
def assert_generated_file(path)
assert_file_exists(path)
- File.open(File.join(@rails_root, path)) do |file|
- yield file.read if block_given?
+ if block_given?
+ File.open(File.join(@rails_root, path)) do |file|
+ expected = yield
+ body = file.read
+ assert body.include?(expected),
+ "expected #{expected} but was #{body.inspect}"
+ end
end
end
@@ -60,8 +23,8 @@ module Test::Unit::Assertions
def assert_generated_views_for(name, *actions)
actions.each do |action|
- assert_generated_file("app/views/#{name}/#{action}.html.erb") do |body|
- yield body if block_given?
+ assert_generated_file("app/views/#{name}/#{action}.html.erb") do
+ yield if block_given?
end
end
end
@@ -69,18 +32,14 @@ module Test::Unit::Assertions
def assert_generated_migration(name)
file = Dir.glob("#{@rails_root}/db/migrate/*_#{name}.rb").first
file = file.match(/db\/migrate\/[0-9]+_\w+/).to_s << ".rb"
- assert_generated_file file do |body|
- assert_match /timestamps/, body, "should have timestamps defined"
- yield body if block_given?
- end
+ assert_generated_file(file) { "timestamps" }
+ assert_generated_file(file) { yield if block_given? }
end
def assert_generated_route_for(name, *actions)
- assert_generated_file("config/routes.rb") do |body|
- routeable_actions = actions.collect { |action| ":#{action}" }.join(", ")
- expected = " map.resources :#{name.to_s}, :only => [#{routeable_actions}]"
- assert body.include?(expected),
- "expected #{expected} but was #{body.inspect}"
+ routeable_actions = actions.collect { |action| ":#{action}" }.join(", ")
+ assert_generated_file("config/routes.rb") do
+ " map.resources :#{name.to_s}, :only => [#{routeable_actions}]"
end
end
diff --git a/vendor/plugins/coulda/features/view_generator.feature b/vendor/plugins/coulda/features/view_generator.feature
index 19a8c3b..f8d8e17 100644
--- a/vendor/plugins/coulda/features/view_generator.feature
+++ b/vendor/plugins/coulda/features/view_generator.feature
@@ -1,12 +1,11 @@
-Feature: Rails controller generator
- In order to better do Test-Driven Development with Rails
- As a user
- I want to generate Shoulda & Factory Girl tests for only RESTful actions I need.
+Feature: Rails view generator
+ In order to do Test-Driven Development with Rails
+ As a developer
+ I want to generate a view to make a functional test pass
- Scenario: View generator for new action when Cucumber is installed
- Given a Rails app with Cucumber
+ Scenario: View generator for new action
+ Given a Rails app
And the coulda plugin is installed
When I generate a "new" view for "Posts"
Then a standard "new" view for "posts" should be generated
- And a standard "posts" feature for the "new" scenario should be generated
diff --git a/vendor/plugins/coulda/generators/controller/controller_generator.rb b/vendor/plugins/coulda/generators/controller/controller_generator.rb
index d5be929..550527a 100644
--- a/vendor/plugins/coulda/generators/controller/controller_generator.rb
+++ b/vendor/plugins/coulda/generators/controller/controller_generator.rb
@@ -1,4 +1,4 @@
-require File.join(File.dirname(__FILE__), "..", "support", "insert_commands")
+require File.join(File.dirname(__FILE__), "..", "support", "generator_helper")
class ControllerGenerator < Rails::Generator::NamedBase
def manifest
@@ -17,9 +17,6 @@ class ControllerGenerator < Rails::Generator::NamedBase
File.join('test/functional',
class_path,
"#{file_name}_controller_test.rb")
-
- m.insert_into "config/routes.rb",
- "map.resources :#{file_name}, :only => [#{routeable_actions}]"
end
end
diff --git a/vendor/plugins/coulda/generators/controller/templates/controller.rb b/vendor/plugins/coulda/generators/controller/templates/controller.rb
index ea75b75..b1fcb6f 100644
--- a/vendor/plugins/coulda/generators/controller/templates/controller.rb
+++ b/vendor/plugins/coulda/generators/controller/templates/controller.rb
@@ -1,8 +1,4 @@
class <%= class_name %>Controller < ApplicationController
-<% resource = file_name.singularize -%>
-<% resources = file_name.pluralize -%>
-<% resource_class = class_name.singularize -%>
-
<% if actions.include?("index") -%>
def index
end
diff --git a/vendor/plugins/coulda/generators/controller/templates/functional_test.rb b/vendor/plugins/coulda/generators/controller/templates/functional_test.rb
index 8df1d42..ef9a2a4 100644
--- a/vendor/plugins/coulda/generators/controller/templates/functional_test.rb
+++ b/vendor/plugins/coulda/generators/controller/templates/functional_test.rb
@@ -1,10 +1,6 @@
require 'test_helper'
class <%= class_name %>ControllerTest < ActionController::TestCase
-<% resource = file_name.singularize -%>
-<% resources = file_name.pluralize -%>
-<% resource_class = class_name.singularize -%>
-
<% if actions.include?("index") -%>
context 'GET to index' do
setup { get :index }
diff --git a/vendor/plugins/coulda/generators/feature/feature_generator.rb b/vendor/plugins/coulda/generators/feature/feature_generator.rb
new file mode 100644
index 0000000..9bb0ccb
--- /dev/null
+++ b/vendor/plugins/coulda/generators/feature/feature_generator.rb
@@ -0,0 +1,28 @@
+require File.join(File.dirname(__FILE__), "..", "support", "generator_helper")
+
+class FeatureGenerator < Rails::Generator::NamedBase
+ def manifest
+ record do |m|
+ m.directory 'features'
+ m.directory 'features/step_definitions'
+ m.directory 'features/support'
+
+ path = File.join('features', "#{resources}.feature")
+ m.template 'feature.feature', path
+
+ path = File.join('features', 'step_definitions', "#{resources}_steps.rb")
+ m.template 'step_definition.rb', path
+
+ path = File.join('features', 'support', "paths.rb")
+ m.insert_into path, insertable_path
+ end
+ end
+
+ def insertable_path
+ if %w(new create).any? { |action| actions.include?(action) }
+ " when /the new #{resource} page/i\n" <<
+ " new_#{resource}_path\n"
+ end
+ end
+end
+
diff --git a/vendor/plugins/coulda/generators/feature/templates/feature.feature b/vendor/plugins/coulda/generators/feature/templates/feature.feature
new file mode 100644
index 0000000..fb72b06
--- /dev/null
+++ b/vendor/plugins/coulda/generators/feature/templates/feature.feature
@@ -0,0 +1,6 @@
+<% if %w(new create).any? { |action| actions.include?(action) } -%>
+ Scenario: Create a new <%= resource %>
+ Given I am on the new <%= resource %> page
+ When I create a <%= resource %> named "A new <%= resource %>"
+ Then I should see "A new <%= resource %>"
+<% end -%>
diff --git a/vendor/plugins/coulda/generators/feature/templates/step_definition.rb b/vendor/plugins/coulda/generators/feature/templates/step_definition.rb
new file mode 100644
index 0000000..a0006b7
--- /dev/null
+++ b/vendor/plugins/coulda/generators/feature/templates/step_definition.rb
@@ -0,0 +1,4 @@
+When /^I create a <%= resource %> named "([^\"]*)"$/ do |name|
+ fills_in :name, :with => name
+ click_button 'Create'
+end
diff --git a/vendor/plugins/coulda/generators/helper/helper_generator.rb b/vendor/plugins/coulda/generators/helper/helper_generator.rb
index baf1e31..2eb4f83 100644
--- a/vendor/plugins/coulda/generators/helper/helper_generator.rb
+++ b/vendor/plugins/coulda/generators/helper/helper_generator.rb
@@ -1,3 +1,5 @@
+require File.join(File.dirname(__FILE__), "..", "support", "generator_helper")
+
class HelperGenerator < Rails::Generator::NamedBase
def manifest
record do |m|
diff --git a/vendor/plugins/coulda/generators/model/model_generator.rb b/vendor/plugins/coulda/generators/model/model_generator.rb
index 9bef5b9..9a3aa57 100644
--- a/vendor/plugins/coulda/generators/model/model_generator.rb
+++ b/vendor/plugins/coulda/generators/model/model_generator.rb
@@ -1,3 +1,5 @@
+require File.join(File.dirname(__FILE__), "..", "support", "generator_helper")
+
class ModelGenerator < Rails::Generator::NamedBase
default_options :skip_timestamps => false,
:skip_migration => false,
diff --git a/vendor/plugins/coulda/generators/model/templates/unit_test.rb b/vendor/plugins/coulda/generators/model/templates/unit_test.rb
index f8ab510..9021608 100644
--- a/vendor/plugins/coulda/generators/model/templates/unit_test.rb
+++ b/vendor/plugins/coulda/generators/model/templates/unit_test.rb
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/../test_helper'
+require 'test_helper'
class <%= class_name %>Test < ActiveSupport::TestCase
should "be valid with factory" do
@@ -12,5 +12,5 @@ class <%= class_name %>Test < ActiveSupport::TestCase
<% if attribute.type == :paperclip -%>
should_have_attached_file :<%= attribute.name %>
<% end -%>
-<% end -%>
+<% end -%>
end
diff --git a/vendor/plugins/coulda/generators/support/generator_helper.rb b/vendor/plugins/coulda/generators/support/generator_helper.rb
new file mode 100644
index 0000000..435e41e
--- /dev/null
+++ b/vendor/plugins/coulda/generators/support/generator_helper.rb
@@ -0,0 +1,31 @@
+require File.join(File.dirname(__FILE__), "insert_commands")
+
+module Coulda
+ module GeneratorHelper
+ REMOVABLE_COLUMNS = ["created_at", "updated_at", "email_confirmed",
+ "encrypted_password", "salt", "token", "token_expires_at"]
+
+ def resource
+ file_name.singularize
+ end
+
+ def resources
+ file_name.pluralize
+ end
+
+ def resource_class
+ class_name.singularize
+ end
+
+ def columns_for_form
+ resource_class.content_columns.
+ collect { |column| [column.name, column.type] }.
+ delete_if { |column| REMOVABLE_COLUMNS.include?(column.first) }
+ end
+ end
+end
+
+class Rails::Generator::NamedBase
+ include Coulda::GeneratorHelper
+end
+
diff --git a/vendor/plugins/coulda/generators/support/insert_commands.rb b/vendor/plugins/coulda/generators/support/insert_commands.rb
index eb648e0..4744a62 100644
--- a/vendor/plugins/coulda/generators/support/insert_commands.rb
+++ b/vendor/plugins/coulda/generators/support/insert_commands.rb
@@ -9,10 +9,15 @@ end
Rails::Generator::Commands::Create.class_eval do
def insert_into(file, line)
logger.insert "#{line} into #{file}"
- unless options[:pretend] || file_contains?(file, line)
- start_of_routes_file = "ActionController::Routing::Routes.draw"
- gsub_file file, /^(class|module|#{start_of_routes_file}) .+$/ do |match|
- "#{match}\n #{line}"
+ unless file_contains?(file, line)
+ if file =~ /^module NavigationHelpers/
+ gsub_file file, /#{Coulda::Insertable.cucumber_paths}/ do |match|
+ "#{match}\n#{line}"
+ end
+ else
+ gsub_file file, /^(class|module|#{Coulda::Insertable.routes}) .+$/ do |match|
+ "#{match}\n #{line}"
+ end
end
end
end
@@ -21,9 +26,7 @@ end
Rails::Generator::Commands::Destroy.class_eval do
def insert_into(file, line)
logger.remove "#{line} from #{file}"
- unless options[:pretend]
- gsub_file file, "\n #{line}", ''
- end
+ gsub_file file, "\n #{line}", ''
end
end
@@ -33,3 +36,15 @@ Rails::Generator::Commands::List.class_eval do
end
end
+module Coulda
+ module Insertable
+ def self.routes
+ "ActionController::Routing::Routes.draw"
+ end
+
+ def self.cucumber_paths
+ "case page_name\n"
+ end
+ end
+end
+
diff --git a/vendor/plugins/coulda/generators/view/templates/feature.feature b/vendor/plugins/coulda/generators/view/templates/feature.feature
deleted file mode 100644
index 5a71b7e..0000000
--- a/vendor/plugins/coulda/generators/view/templates/feature.feature
+++ /dev/null
@@ -1,10 +0,0 @@
-<% resource = file_name.singularize -%>
-<% resources = file_name.pluralize -%>
-<% resource_class = class_name.singularize -%>
-
-<% if %w(new create).any? { |action| actions.include?(action) } -%>
- Scenario: Create a new '<%= resource %>'
- Given I am on the new <%= resource %> page
- When I create a '<%= resource %>' named 'A new <%= resource %>'
- Then I should see 'A new <%= resource %>'
-<% end -%>
diff --git a/vendor/plugins/coulda/generators/view/templates/view_new.html.erb b/vendor/plugins/coulda/generators/view/templates/view_new.html.erb
index 52b89ac..a85dd14 100644
--- a/vendor/plugins/coulda/generators/view/templates/view_new.html.erb
+++ b/vendor/plugins/coulda/generators/view/templates/view_new.html.erb
@@ -1,4 +1,3 @@
-<% resource = file_name.singularize -%>
New <%= resource %>
<%% form_for(@<%= resource %>) do |form| %>
diff --git a/vendor/plugins/coulda/generators/view/templates/view_show.html.erb b/vendor/plugins/coulda/generators/view/templates/view_show.html.erb
index 3393646..71375ad 100644
--- a/vendor/plugins/coulda/generators/view/templates/view_show.html.erb
+++ b/vendor/plugins/coulda/generators/view/templates/view_show.html.erb
@@ -1,4 +1,4 @@
-<%= singular_name %>
+<%= resource %>
-<%%= link_to 'Edit', edit_<%= singular_name %>_path(@<%= singular_name %>) %>
+<%%= link_to 'Edit', edit_<%= resource %>_path(@<%= resource %>) %>
diff --git a/vendor/plugins/coulda/generators/view/view_generator.rb b/vendor/plugins/coulda/generators/view/view_generator.rb
index f2f865f..a87426a 100644
--- a/vendor/plugins/coulda/generators/view/view_generator.rb
+++ b/vendor/plugins/coulda/generators/view/view_generator.rb
@@ -1,15 +1,13 @@
+require File.join(File.dirname(__FILE__), "..", "support", "generator_helper")
+
class ViewGenerator < Rails::Generator::NamedBase
def manifest
record do |m|
m.directory File.join('app/views', class_path, file_name)
- m.directory 'features'
if actions.include?("new")
path = File.join('app/views', class_path, file_name, "new.html.erb")
m.template 'view_new.html.erb', path
-
- path = File.join('features', "#{file_name.pluralize}.feature")
- m.template 'feature.feature', path
end
end
end
--
libgit2 0.21.2