我通过Ruby on Rails的教程3运行,并且有一个球做,但我刚刚遇到的是没有得到解决的问题。当我运行我的规格时,两个测试失败。Rails的教程3,RSpec的失败
Failures:
1) UsersController PUT 'update' failure should render the 'edit' page
Failure/Error: put :update, :id => @user, :user => @attr
undefined local variable or method `object' for #<#<Class:0x00000102c861c8>:0x00000101d25558>
# ./app/views/shared/_error_messages.html.erb:3:in `_app_views_shared__error_messages_html_erb___3390867530789228804_2170854120__2806434579894406668'
# ./app/views/users/edit.html.erb:4:in `block in _app_views_users_edit_html_erb__558009768664311469_2170714160__919273585470661416'
# ./app/views/users/edit.html.erb:3:in `_app_views_users_edit_html_erb__558009768664311469_2170714160__919273585470661416'
# ./app/controllers/users_controller.rb:47:in `update'
# ./spec/controllers/users_controller_spec.rb:158:in `block (4 levels) in <top (required)>'
2) UsersController PUT 'update' failure should have the right title
Failure/Error: put :update, :id => @user, :user => @attr
undefined local variable or method `object' for #<#<Class:0x00000102c861c8>:0x00000101b211f8>
# ./app/views/shared/_error_messages.html.erb:3:in `_app_views_shared__error_messages_html_erb___3390867530789228804_2170854120__2806434579894406668'
# ./app/views/users/edit.html.erb:4:in `block in _app_views_users_edit_html_erb__558009768664311469_2170714160__919273585470661416'
# ./app/views/users/edit.html.erb:3:in `_app_views_users_edit_html_erb__558009768664311469_2170714160__919273585470661416'
# ./app/controllers/users_controller.rb:47:in `update'
# ./spec/controllers/users_controller_spec.rb:163:in `block (4 levels) in <top (required)>'
我已经通过我的代码作为最好的,我可以比较反对它在书中的代码搜索,我想出了什么。我相信这是我错过的一件愚蠢的小事,我会非常感激第二双(或更多)眼睛。
这里是我的测试:
describe "failure" do
before(:each) do
@attr = { :email => "", :name => "", :password => "", :password_confirmation => "" }
end
it "should render the 'edit' page" do
put :update, :id => @user, :user => @attr
response.should render_template('edit')
end
it "should have the right title" do
put :update, :id => @user, :user => @attr
response.should have_selector("title", :content => "Edit User")
end
end
这里是从users_controller更新方法:
def update
@user = User.find(params[:id])
if @user.update_attributes(params[:user])
flash[:success] = "Profile updated"
redirect_to @user
else
@title = "Edit User"
render 'edit'
end
end
在哪里我应该是极大的赞赏任何想法。
从您的_error_messages.html.erb降临到你的错误:3模板? – monocle 2011-06-11 01:48:15
您可以发布app/views/shared/_error_messages.html.erb的内容吗? – 2011-06-11 02:02:03
非常感谢你们!你指出我正确的方向。问题不在于error_messages.html.erb;它在我的edit.html.erb中,这是我应该创建它所抱怨的'object'变量的地方。你是最好的! – YuKagi 2011-06-11 03:24:02