Added Rspec and Webrat plugins and started porting Selenium on Rails tests to Rspec Plain Text Stories driving Webrat driving Selenium.

This commit is contained in:
Luke Melia 2008-06-18 02:57:57 -04:00
parent 0600756bbf
commit 0f7d6f7a1d
602 changed files with 47788 additions and 29 deletions

View file

@ -0,0 +1,33 @@
Description:
The rspec_controller generator creates stub specs and files for a new
controller and its views.
The generator takes a controller name and a list of views as arguments.
The controller name may be given in CamelCase or under_score and should
not be suffixed with 'Controller'. To create a controller within a
module, specify the controller name as 'module/controller'.
The generator creates stubs for a controller (and spec), a view (and spec)
for each view in the argument list, plus a helper.
Example:
./script/generate rspec_controller dog bark fetch
...
create spec/controllers/dog_controller_spec.rb
create app/controllers/dog_controller.rb
create app/helpers/dog_helper.rb
create spec/views/dog/bark_view_spec.rb
create app/views/dog/bark.rhtml
create spec/views/dog/fetch_view_spec.rb
create app/views/dog/fetch.rhtml
Modules Example:
./script/generate rspec_controller 'pets/dog' bark fetch
...
create spec/controllers/pets/dog_controller_spec.rb
create app/controllers/pets/dog_controller.rb
create app/helpers/pets/dog_helper.rb
create spec/views/pets/dog/bark_view_spec.rb
create app/views/pets/dog/bark.rhtml
create spec/views/pets/dog/fetch_view_spec.rb
create app/views/pets/dog/fetch.rhtml

View file

@ -0,0 +1,49 @@
require 'rails_generator/generators/components/controller/controller_generator'
class RspecControllerGenerator < ControllerGenerator
def manifest
record do |m|
# Check for class naming collisions.
m.class_collisions class_path, "#{class_name}Controller", "#{class_name}Helper"
# Controller, helper, views, and spec directories.
m.directory File.join('app/controllers', class_path)
m.directory File.join('app/helpers', class_path)
m.directory File.join('app/views', class_path, file_name)
m.directory File.join('spec/controllers', class_path)
m.directory File.join('spec/helpers', class_path)
m.directory File.join('spec/views', class_path, file_name)
if Rails::VERSION::STRING < "2.0.0"
@default_file_extension = "rhtml"
else
@default_file_extension = "html.erb"
end
# Controller spec, class, and helper.
m.template 'controller_spec.rb',
File.join('spec/controllers', class_path, "#{file_name}_controller_spec.rb")
m.template 'helper_spec.rb',
File.join('spec/helpers', class_path, "#{file_name}_helper_spec.rb")
m.template 'controller:controller.rb',
File.join('app/controllers', class_path, "#{file_name}_controller.rb")
m.template 'controller:helper.rb',
File.join('app/helpers', class_path, "#{file_name}_helper.rb")
# Spec and view template for each action.
actions.each do |action|
m.template 'view_spec.rb',
File.join('spec/views', class_path, file_name, "#{action}.#{@default_file_extension}_spec.rb"),
:assigns => { :action => action, :model => file_name }
path = File.join('app/views', class_path, file_name, "#{action}.#{@default_file_extension}")
m.template "controller:view.#{@default_file_extension}",
path,
:assigns => { :action => action, :path => path }
end
end
end
end

View file

@ -0,0 +1,25 @@
require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../spec_helper')
describe <%= class_name %>Controller do
<% if actions.empty? -%>
#Delete this example and add some real ones
<% else -%>
#Delete these examples and add some real ones
<% end -%>
it "should use <%= class_name %>Controller" do
controller.should be_an_instance_of(<%= class_name %>Controller)
end
<% unless actions.empty? -%>
<% for action in actions -%>
describe "GET '<%= action %>'" do
it "should be successful" do
get '<%= action %>'
response.should be_success
end
end
<% end -%>
<% end -%>
end

View file

@ -0,0 +1,11 @@
require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../spec_helper')
describe <%= class_name %>Helper do
#Delete this example and add some real ones or delete this file
it "should be included in the object returned by #helper" do
included_modules = (class << helper; self; end).send :included_modules
included_modules.should include(<%= class_name %>Helper)
end
end

View file

@ -0,0 +1,12 @@
require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../../spec_helper')
describe "/<%= class_name.underscore %>/<%= action %>" do
before(:each) do
render '<%= class_name.underscore %>/<%= action %>'
end
#Delete this example and add some real ones or delete this file
it "should tell you where to find the file" do
response.should have_tag('p', %r[Find me in app/views/<%= class_name.underscore %>/<%= action %>])
end
end