这里是我的现任用户——控制者——光谱。
require spec_helper
describe UsersController do
render_views
.
.
.
describe "success" do
before(:each) do
@attr = { :name => "New User", :email => "[email protected]",
:password => "foobar", :password_confirmation => "foobar" }
end
it "should create a user" do
lambda do
post :create, :user => @attr
end.should change(User, :count).by(1)
end
it "should redirect to the user show page" do
post :create, :user => @attr
response.should redirect_to(user_path(assigns(:user)))
end
end
end
end
当我执政时,我得到以下信息:
Failures:
1) UsersController POST create success should redirect to the user show page
Failure/Error: response.should redirect_to(user_path(user))
ActionController::RoutingError:
No route matches {:action=>"show", :controller=>"users"}
# ./spec/controllers/users_controller_spec.rb:95:in `block (4 levels) in <top (required)>
这使我相信:用户是实际物体。 我如何测试这一点,以及我如何改变:用户变成用户能理解的物体。
事先得到任何帮助。
<>执行>:
def create
@title = "Sign up"
@user = User.new(params[:user])
if @user.save
redirect_to @user, :notice => "Signed Up!"
else
@title = "Sign up"
render "new"
end
end
在我执政时:
it "should redirect to the user show page" do
post :create, :user => @attr
user = assigns(:user)
user.should_not be_blank
puts "user errors are: #{user.errors.full_messages.inspect}" unless user.is_valid?
user.should be_valid
response.should redirect_to(user_path(user))
end
我收到了:
1) UsersController POST create success should redirect to the user show page
Failure/Error: user.should_not be_blank
expected blank? to return false, got true
# ./spec/controllers/users_controller_spec.rb:94:in `block (4 levels) in <top (required)>