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,313 @@
require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../spec_helper')
describe <%= controller_class_name %>Controller do
describe "handling GET /<%= table_name %>" do
before(:each) do
@<%= file_name %> = mock_model(<%= class_name %>)
<%= class_name %>.stub!(:find).and_return([@<%= file_name %>])
end
def do_get
get :index
end
it "should be successful" do
do_get
response.should be_success
end
it "should render index template" do
do_get
response.should render_template('index')
end
it "should find all <%= table_name %>" do
<%= class_name %>.should_receive(:find).with(:all).and_return([@<%= file_name %>])
do_get
end
it "should assign the found <%= table_name %> for the view" do
do_get
assigns[:<%= table_name %>].should == [@<%= file_name %>]
end
end
describe "handling GET /<%= table_name %>.xml" do
before(:each) do
@<%= file_name.pluralize %> = mock("Array of <%= class_name.pluralize %>", :to_xml => "XML")
<%= class_name %>.stub!(:find).and_return(@<%= file_name.pluralize %>)
end
def do_get
@request.env["HTTP_ACCEPT"] = "application/xml"
get :index
end
it "should be successful" do
do_get
response.should be_success
end
it "should find all <%= table_name %>" do
<%= class_name %>.should_receive(:find).with(:all).and_return(@<%= file_name.pluralize %>)
do_get
end
it "should render the found <%= table_name %> as xml" do
@<%= file_name.pluralize %>.should_receive(:to_xml).and_return("XML")
do_get
response.body.should == "XML"
end
end
describe "handling GET /<%= table_name %>/1" do
before(:each) do
@<%= file_name %> = mock_model(<%= class_name %>)
<%= class_name %>.stub!(:find).and_return(@<%= file_name %>)
end
def do_get
get :show, :id => "1"
end
it "should be successful" do
do_get
response.should be_success
end
it "should render show template" do
do_get
response.should render_template('show')
end
it "should find the <%= file_name %> requested" do
<%= class_name %>.should_receive(:find).with("1").and_return(@<%= file_name %>)
do_get
end
it "should assign the found <%= file_name %> for the view" do
do_get
assigns[:<%= file_name %>].should equal(@<%= file_name %>)
end
end
describe "handling GET /<%= table_name %>/1.xml" do
before(:each) do
@<%= file_name %> = mock_model(<%= class_name %>, :to_xml => "XML")
<%= class_name %>.stub!(:find).and_return(@<%= file_name %>)
end
def do_get
@request.env["HTTP_ACCEPT"] = "application/xml"
get :show, :id => "1"
end
it "should be successful" do
do_get
response.should be_success
end
it "should find the <%= file_name %> requested" do
<%= class_name %>.should_receive(:find).with("1").and_return(@<%= file_name %>)
do_get
end
it "should render the found <%= file_name %> as xml" do
@<%= file_name %>.should_receive(:to_xml).and_return("XML")
do_get
response.body.should == "XML"
end
end
describe "handling GET /<%= table_name %>/new" do
before(:each) do
@<%= file_name %> = mock_model(<%= class_name %>)
<%= class_name %>.stub!(:new).and_return(@<%= file_name %>)
end
def do_get
get :new
end
it "should be successful" do
do_get
response.should be_success
end
it "should render new template" do
do_get
response.should render_template('new')
end
it "should create an new <%= file_name %>" do
<%= class_name %>.should_receive(:new).and_return(@<%= file_name %>)
do_get
end
it "should not save the new <%= file_name %>" do
@<%= file_name %>.should_not_receive(:save)
do_get
end
it "should assign the new <%= file_name %> for the view" do
do_get
assigns[:<%= file_name %>].should equal(@<%= file_name %>)
end
end
describe "handling GET /<%= table_name %>/1/edit" do
before(:each) do
@<%= file_name %> = mock_model(<%= class_name %>)
<%= class_name %>.stub!(:find).and_return(@<%= file_name %>)
end
def do_get
get :edit, :id => "1"
end
it "should be successful" do
do_get
response.should be_success
end
it "should render edit template" do
do_get
response.should render_template('edit')
end
it "should find the <%= file_name %> requested" do
<%= class_name %>.should_receive(:find).and_return(@<%= file_name %>)
do_get
end
it "should assign the found <%= class_name %> for the view" do
do_get
assigns[:<%= file_name %>].should equal(@<%= file_name %>)
end
end
describe "handling POST /<%= table_name %>" do
before(:each) do
@<%= file_name %> = mock_model(<%= class_name %>, :to_param => "1")
<%= class_name %>.stub!(:new).and_return(@<%= file_name %>)
end
describe "with successful save" do
def do_post
@<%= file_name %>.should_receive(:save).and_return(true)
post :create, :<%= file_name %> => {}
end
it "should create a new <%= file_name %>" do
<%= class_name %>.should_receive(:new).with({}).and_return(@<%= file_name %>)
do_post
end
it "should redirect to the new <%= file_name %>" do
do_post
response.should redirect_to(<%= table_name.singularize %>_url("1"))
end
end
describe "with failed save" do
def do_post
@<%= file_name %>.should_receive(:save).and_return(false)
post :create, :<%= file_name %> => {}
end
it "should re-render 'new'" do
do_post
response.should render_template('new')
end
end
end
describe "handling PUT /<%= table_name %>/1" do
before(:each) do
@<%= file_name %> = mock_model(<%= class_name %>, :to_param => "1")
<%= class_name %>.stub!(:find).and_return(@<%= file_name %>)
end
describe "with successful update" do
def do_put
@<%= file_name %>.should_receive(:update_attributes).and_return(true)
put :update, :id => "1"
end
it "should find the <%= file_name %> requested" do
<%= class_name %>.should_receive(:find).with("1").and_return(@<%= file_name %>)
do_put
end
it "should update the found <%= file_name %>" do
do_put
assigns(:<%= file_name %>).should equal(@<%= file_name %>)
end
it "should assign the found <%= file_name %> for the view" do
do_put
assigns(:<%= file_name %>).should equal(@<%= file_name %>)
end
it "should redirect to the <%= file_name %>" do
do_put
response.should redirect_to(<%= table_name.singularize %>_url("1"))
end
end
describe "with failed update" do
def do_put
@<%= file_name %>.should_receive(:update_attributes).and_return(false)
put :update, :id => "1"
end
it "should re-render 'edit'" do
do_put
response.should render_template('edit')
end
end
end
describe "handling DELETE /<%= table_name %>/1" do
before(:each) do
@<%= file_name %> = mock_model(<%= class_name %>, :destroy => true)
<%= class_name %>.stub!(:find).and_return(@<%= file_name %>)
end
def do_delete
delete :destroy, :id => "1"
end
it "should find the <%= file_name %> requested" do
<%= class_name %>.should_receive(:find).with("1").and_return(@<%= file_name %>)
do_delete
end
it "should call destroy on the found <%= file_name %>" do
@<%= file_name %>.should_receive(:destroy)
do_delete
end
it "should redirect to the <%= table_name %> list" do
do_delete
response.should redirect_to(<%= table_name %>_url)
end
end
end

View file

@ -0,0 +1,25 @@
require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../../spec_helper')
describe "/<%= table_name %>/edit.<%= default_file_extension %>" do
include <%= controller_class_name %>Helper
before do
@<%= file_name %> = mock_model(<%= class_name %>)
<% for attribute in attributes -%>
@<%= file_name %>.stub!(:<%= attribute.name %>).and_return(<%= attribute.default_value %>)
<% end -%>
assigns[:<%= file_name %>] = @<%= file_name %>
end
it "should render edit form" do
render "/<%= table_name %>/edit.<%= default_file_extension %>"
response.should have_tag("form[action=#{<%= file_name %>_path(@<%= file_name %>)}][method=post]") do
<% for attribute in attributes -%><% unless attribute.name =~ /_id/ || [:datetime, :timestamp, :time, :date].index(attribute.type) -%>
with_tag('<%= attribute.input_type -%>#<%= file_name %>_<%= attribute.name %>[name=?]', "<%= file_name %>[<%= attribute.name %>]")
<% end -%><% end -%>
end
end
end

View file

@ -0,0 +1,11 @@
require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../spec_helper')
describe <%= controller_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(<%= controller_class_name %>Helper)
end
end

View file

@ -0,0 +1,22 @@
require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../../spec_helper')
describe "/<%= table_name %>/index.<%= default_file_extension %>" do
include <%= controller_class_name %>Helper
before(:each) do
<% [98,99].each do |id| -%>
<%= file_name %>_<%= id %> = mock_model(<%= class_name %>)
<% for attribute in attributes -%>
<%= file_name %>_<%= id %>.should_receive(:<%= attribute.name %>).and_return(<%= attribute.default_value %>)
<% end -%><% end %>
assigns[:<%= table_name %>] = [<%= file_name %>_98, <%= file_name %>_99]
end
it "should render list of <%= table_name %>" do
render "/<%= table_name %>/index.<%= default_file_extension %>"
<% for attribute in attributes -%><% unless attribute.name =~ /_id/ || [:datetime, :timestamp, :time, :date].index(attribute.type) -%>
response.should have_tag("tr>td", <%= attribute.default_value %>, 2)
<% end -%><% end -%>
end
end

View file

@ -0,0 +1,26 @@
require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../../spec_helper')
describe "/<%= table_name %>/new.<%= default_file_extension %>" do
include <%= controller_class_name %>Helper
before(:each) do
@<%= file_name %> = mock_model(<%= class_name %>)
@<%= file_name %>.stub!(:new_record?).and_return(true)
<% for attribute in attributes -%>
@<%= file_name %>.stub!(:<%= attribute.name %>).and_return(<%= attribute.default_value %>)
<% end -%>
assigns[:<%= file_name %>] = @<%= file_name %>
end
it "should render new form" do
render "/<%= table_name %>/new.<%= default_file_extension %>"
response.should have_tag("form[action=?][method=post]", <%= table_name %>_path) do
<% for attribute in attributes -%><% unless attribute.name =~ /_id/ || [:datetime, :timestamp, :time, :date].index(attribute.type) -%>
with_tag("<%= attribute.input_type -%>#<%= file_name %>_<%= attribute.name %>[name=?]", "<%= file_name %>[<%= attribute.name %>]")
<% end -%><% end -%>
end
end
end

View file

@ -0,0 +1,61 @@
require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../spec_helper')
describe <%= controller_class_name %>Controller do
describe "route generation" do
it "should map { :controller => '<%= table_name %>', :action => 'index' } to /<%= table_name %>" do
route_for(:controller => "<%= table_name %>", :action => "index").should == "/<%= table_name %>"
end
it "should map { :controller => '<%= table_name %>', :action => 'new' } to /<%= table_name %>/new" do
route_for(:controller => "<%= table_name %>", :action => "new").should == "/<%= table_name %>/new"
end
it "should map { :controller => '<%= table_name %>', :action => 'show', :id => 1 } to /<%= table_name %>/1" do
route_for(:controller => "<%= table_name %>", :action => "show", :id => 1).should == "/<%= table_name %>/1"
end
it "should map { :controller => '<%= table_name %>', :action => 'edit', :id => 1 } to /<%= table_name %>/1<%= resource_edit_path %>" do
route_for(:controller => "<%= table_name %>", :action => "edit", :id => 1).should == "/<%= table_name %>/1<%= resource_edit_path %>"
end
it "should map { :controller => '<%= table_name %>', :action => 'update', :id => 1} to /<%= table_name %>/1" do
route_for(:controller => "<%= table_name %>", :action => "update", :id => 1).should == "/<%= table_name %>/1"
end
it "should map { :controller => '<%= table_name %>', :action => 'destroy', :id => 1} to /<%= table_name %>/1" do
route_for(:controller => "<%= table_name %>", :action => "destroy", :id => 1).should == "/<%= table_name %>/1"
end
end
describe "route recognition" do
it "should generate params { :controller => '<%= table_name %>', action => 'index' } from GET /<%= table_name %>" do
params_from(:get, "/<%= table_name %>").should == {:controller => "<%= table_name %>", :action => "index"}
end
it "should generate params { :controller => '<%= table_name %>', action => 'new' } from GET /<%= table_name %>/new" do
params_from(:get, "/<%= table_name %>/new").should == {:controller => "<%= table_name %>", :action => "new"}
end
it "should generate params { :controller => '<%= table_name %>', action => 'create' } from POST /<%= table_name %>" do
params_from(:post, "/<%= table_name %>").should == {:controller => "<%= table_name %>", :action => "create"}
end
it "should generate params { :controller => '<%= table_name %>', action => 'show', id => '1' } from GET /<%= table_name %>/1" do
params_from(:get, "/<%= table_name %>/1").should == {:controller => "<%= table_name %>", :action => "show", :id => "1"}
end
it "should generate params { :controller => '<%= table_name %>', action => 'edit', id => '1' } from GET /<%= table_name %>/1;edit" do
params_from(:get, "/<%= table_name %>/1<%= resource_edit_path %>").should == {:controller => "<%= table_name %>", :action => "edit", :id => "1"}
end
it "should generate params { :controller => '<%= table_name %>', action => 'update', id => '1' } from PUT /<%= table_name %>/1" do
params_from(:put, "/<%= table_name %>/1").should == {:controller => "<%= table_name %>", :action => "update", :id => "1"}
end
it "should generate params { :controller => '<%= table_name %>', action => 'destroy', id => '1' } from DELETE /<%= table_name %>/1" do
params_from(:delete, "/<%= table_name %>/1").should == {:controller => "<%= table_name %>", :action => "destroy", :id => "1"}
end
end
end

View file

@ -0,0 +1,22 @@
require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../../spec_helper')
describe "/<%= table_name %>/show.<%= default_file_extension %>" do
include <%= controller_class_name %>Helper
before(:each) do
@<%= file_name %> = mock_model(<%= class_name %>)
<% for attribute in attributes -%>
@<%= file_name %>.stub!(:<%= attribute.name %>).and_return(<%= attribute.default_value %>)
<% end -%>
assigns[:<%= file_name %>] = @<%= file_name %>
end
it "should render attributes in <p>" do
render "/<%= table_name %>/show.<%= default_file_extension %>"
<% for attribute in attributes -%><% unless attribute.name =~ /_id/ || [:datetime, :timestamp, :time, :date].index(attribute.type) -%>
response.should have_text(/<%= Regexp.escape(attribute.default_value)[1..-2]%>/)
<% end -%><% end -%>
end
end