失败/错误:response.should redirect_to(signin_path)

时间:2011-09-16 17:57:31

标签: ruby-on-rails ruby

如果我不使用“before_filter:authenticate,:only => [:edit]”,我会收到此错误 失败/错误:response.should redirect_to(signin_path) 如果我添加“before_filter:authenticate,:only => [:edit]”iam得到一些其他错误,如

1) UsersController GET 'edit' should be successfull
     Failure/Error: response.should be_success
       expected success? to return true, got false
     # ./spec/controllers/users_controller_spec.rb:102:in `block (3 levels) in <top (required)>'

  2) UsersController GET 'edit' should have the right title
     Failure/Error: response.should have_selector('title', :content => "Edit user")
       expected following output to contain a <title>Edit user</title> tag:
       <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
       <html><body>You are being <a href="http://test.host/signin">redirected</a>.</body></html>
     # ./spec/controllers/users_controller_spec.rb:106:in `block (3 levels) in <top (required)>'

  3) UsersController GET 'edit' should have a link to change the Gravatar
     Failure/Error: response.should have_selector('a', :href => 'http://gravatar.com/emails',
       expected following output to contain a <a href='http://gravatar.com/emails'>change</a> tag:

请建议我一个可能的解决方案......

2 个答案:

答案 0 :(得分:0)

如果您在控制器规范中测试选择器,则需要render_views

describe UsersController do
  render_views
  ...
end

答案 1 :(得分:0)

是的,我得到了......在编辑之前就像这样定义了

def edit
  @user = User.find([:id])
  @title = "Edit user"
end

最后我把它作为

def edit
  @user = User.find(params[:id])
  @title = "Edit user"
end

所以它对我有用.....