Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rspec Rails-模拟当前用户以测试控制器_Ruby On Rails_Rspec - Fatal编程技术网

Ruby on rails Rspec Rails-模拟当前用户以测试控制器

Ruby on rails Rspec Rails-模拟当前用户以测试控制器,ruby-on-rails,rspec,Ruby On Rails,Rspec,我已经开始为我的控制器编写测试。对于其中的一次,我需要登录,以检查页面是否呈现等 由于我使用的Desive在用户模型上有一个当前的用户助手,我如何形成我的: describe "when it GETS 'town'" do it "should render the template and be successful" do get :index response.should render_template(:index) response.should be_

我已经开始为我的控制器编写测试。对于其中的一次,我需要登录,以检查页面是否呈现等

由于我使用的Desive在用户模型上有一个当前的用户助手,我如何形成我的:

describe "when it GETS 'town'" do
  it "should render the template and be successful" do
    get :index
    response.should render_template(:index)
    response.should be_success
  end
end

这样我就不会出现未定义的“authenticate!”方法(特定于设计)错误了?

上有一篇关于这个主题的好文章。基本上,您需要添加designe测试助手,然后在规范需要时调用
sign\u in
以获得有效的当前用户