Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Change a couple of message expectations to stubs in order to clarify

intent in generated controller specs.
  • Loading branch information...
commit 31d652863faf2f8da455b5d3882521d4485b4c38 1 parent 2d89bc9
@dchelimsky dchelimsky authored
View
12 lib/generators/rspec/scaffold/scaffold_generator.rb
@@ -97,21 +97,21 @@ def mock_file_name(hash=nil)
# should! orm_class.find(User, "37")
# #=> User.should_receive(:get).with(37)
#
- def should_receive!(chain)
+ def should_receive(chain)
stub_or_should_chain(:should_receive, chain)
end
# Receives the ORM chain and convert to stub. For ActiveRecord:
#
- # stub! orm_class.find(User, "37")
- # #=> User.stub!(:find).with(37)
+ # stub orm_class.find(User, "37")
+ # #=> User.stub(:find).with(37)
#
# For Datamapper:
#
- # stub! orm_class.find(User, "37")
- # #=> User.stub!(:get).with(37)
+ # stub orm_class.find(User, "37")
+ # #=> User.stub(:get).with(37)
#
- def stub!(chain)
+ def stub(chain)
stub_or_should_chain(:stub, chain)
end
View
38 lib/generators/rspec/scaffold/templates/controller_spec.rb
@@ -1,5 +1,9 @@
require 'spec_helper'
+# This spec was generated by rspec-rails when you ran the scaffold generator.
+# It demonstrates how one might use RSpec to specify the controller code that
+# was generated by the Rails when you ran the scaffold generator.
+
describe <%= controller_class_name %>Controller do
def <%= mock_file_name %>(stubs={})
@@ -11,7 +15,7 @@ def <%= mock_file_name %>(stubs={})
<% unless options[:singleton] -%>
describe "GET index" do
it "assigns all <%= table_name.pluralize %> as @<%= table_name.pluralize %>" do
- <%= stub! orm_class.all(class_name) %> { [<%= mock_file_name %>] }
+ <%= stub orm_class.all(class_name) %> { [<%= mock_file_name %>] }
get :index
assigns(:<%= table_name %>).should eq([<%= mock_file_name %>])
end
@@ -20,7 +24,7 @@ def <%= mock_file_name %>(stubs={})
<% end -%>
describe "GET show" do
it "assigns the requested <%= file_name %> as @<%= file_name %>" do
- <%= stub! orm_class.find(class_name, "37".inspect) %> { <%= mock_file_name %> }
+ <%= stub orm_class.find(class_name, "37".inspect) %> { <%= mock_file_name %> }
get :show, :id => "37"
assigns(:<%= file_name %>).should be(<%= mock_file_name %>)
end
@@ -28,7 +32,7 @@ def <%= mock_file_name %>(stubs={})
describe "GET new" do
it "assigns a new <%= file_name %> as @<%= file_name %>" do
- <%= stub! orm_class.build(class_name) %> { <%= mock_file_name %> }
+ <%= stub orm_class.build(class_name) %> { <%= mock_file_name %> }
get :new
assigns(:<%= file_name %>).should be(<%= mock_file_name %>)
end
@@ -36,7 +40,7 @@ def <%= mock_file_name %>(stubs={})
describe "GET edit" do
it "assigns the requested <%= file_name %> as @<%= file_name %>" do
- <%= stub! orm_class.find(class_name, "37".inspect) %> { <%= mock_file_name %> }
+ <%= stub orm_class.find(class_name, "37".inspect) %> { <%= mock_file_name %> }
get :edit, :id => "37"
assigns(:<%= file_name %>).should be(<%= mock_file_name %>)
end
@@ -46,13 +50,13 @@ def <%= mock_file_name %>(stubs={})
describe "with valid params" do
it "assigns a newly created <%= file_name %> as @<%= file_name %>" do
- <%= stub! orm_class.build(class_name, params) %> { <%= mock_file_name(:save => true) %> }
+ <%= stub orm_class.build(class_name, params) %> { <%= mock_file_name(:save => true) %> }
post :create, :<%= file_name %> => <%= params %>
assigns(:<%= file_name %>).should be(<%= mock_file_name %>)
end
it "redirects to the created <%= file_name %>" do
- <%= stub! orm_class.build(class_name) %> { <%= mock_file_name(:save => true) %> }
+ <%= stub orm_class.build(class_name) %> { <%= mock_file_name(:save => true) %> }
post :create, :<%= file_name %> => {}
response.should redirect_to(<%= table_name.singularize %>_url(<%= mock_file_name %>))
end
@@ -60,13 +64,13 @@ def <%= mock_file_name %>(stubs={})
describe "with invalid params" do
it "assigns a newly created but unsaved <%= file_name %> as @<%= file_name %>" do
- <%= stub! orm_class.build(class_name, params) %> { <%= mock_file_name(:save => false) %> }
+ <%= stub orm_class.build(class_name, params) %> { <%= mock_file_name(:save => false) %> }
post :create, :<%= file_name %> => <%= params %>
assigns(:<%= file_name %>).should be(<%= mock_file_name %>)
end
it "re-renders the 'new' template" do
- <%= stub! orm_class.build(class_name) %> { <%= mock_file_name(:save => false) %> }
+ <%= stub orm_class.build(class_name) %> { <%= mock_file_name(:save => false) %> }
post :create, :<%= file_name %> => {}
response.should render_template("new")
end
@@ -78,19 +82,19 @@ def <%= mock_file_name %>(stubs={})
describe "with valid params" do
it "updates the requested <%= file_name %>" do
- <%= should_receive! orm_class.find(class_name, "37".inspect) %> { <%= mock_file_name %> }
- mock_<%= should_receive! orm_instance.update_attributes(params) %>
+ <%= stub orm_class.find(class_name, "37".inspect) %> { <%= mock_file_name %> }
+ mock_<%= should_receive orm_instance.update_attributes(params) %>
put :update, :id => "37", :<%= file_name %> => <%= params %>
end
it "assigns the requested <%= file_name %> as @<%= file_name %>" do
- <%= stub! orm_class.find(class_name) %> { <%= mock_file_name(:update_attributes => true) %> }
+ <%= stub orm_class.find(class_name) %> { <%= mock_file_name(:update_attributes => true) %> }
put :update, :id => "1"
assigns(:<%= file_name %>).should be(<%= mock_file_name %>)
end
it "redirects to the <%= file_name %>" do
- <%= stub! orm_class.find(class_name) %> { <%= mock_file_name(:update_attributes => true) %> }
+ <%= stub orm_class.find(class_name) %> { <%= mock_file_name(:update_attributes => true) %> }
put :update, :id => "1"
response.should redirect_to(<%= table_name.singularize %>_url(<%= mock_file_name %>))
end
@@ -98,13 +102,13 @@ def <%= mock_file_name %>(stubs={})
describe "with invalid params" do
it "assigns the <%= file_name %> as @<%= file_name %>" do
- <%= stub! orm_class.find(class_name) %> { <%= mock_file_name(:update_attributes => false) %> }
+ <%= stub orm_class.find(class_name) %> { <%= mock_file_name(:update_attributes => false) %> }
put :update, :id => "1"
assigns(:<%= file_name %>).should be(<%= mock_file_name %>)
end
it "re-renders the 'edit' template" do
- <%= stub! orm_class.find(class_name) %> { <%= mock_file_name(:update_attributes => false) %> }
+ <%= stub orm_class.find(class_name) %> { <%= mock_file_name(:update_attributes => false) %> }
put :update, :id => "1"
response.should render_template("edit")
end
@@ -114,13 +118,13 @@ def <%= mock_file_name %>(stubs={})
describe "DELETE destroy" do
it "destroys the requested <%= file_name %>" do
- <%= should_receive! orm_class.find(class_name, "37".inspect) %> { <%= mock_file_name %> }
- mock_<%= should_receive! orm_instance.destroy %>
+ <%= stub orm_class.find(class_name, "37".inspect) %> { <%= mock_file_name %> }
+ mock_<%= should_receive orm_instance.destroy %>
delete :destroy, :id => "37"
end
it "redirects to the <%= table_name %> list" do
- <%= stub! orm_class.find(class_name) %> { <%= mock_file_name %> }
+ <%= stub orm_class.find(class_name) %> { <%= mock_file_name %> }
delete :destroy, :id => "1"
response.should redirect_to(<%= table_name %>_url)
end
Please sign in to comment.
Something went wrong with that request. Please try again.