繁体   English   中英

渲染在rspec测试中失败以进行查看

[英]render failing in rspec test for view

在我看来,我有以下几点

require 'spec_helper'

describe "my_project/index.html.erb" do
  it "displays the Country drop down" do
    render
    rendered.should contain("Country")
  end
end

但是当我运行规范时我收到以下错误

Failure/Error: render
 ActionView::Template::Error:
   undefined method `map' for nil:NilClass

我对我的页面确实包含文本时为什么会收到此错误感到困惑。

您需要一个实例变量来使用它吗? 即在控制器索引方法中设置的内容...像这样:

require 'spec_helper'

describe "my_project/index.html.erb" do
  before do
    @some_instance_variable = SomeClass.all
    render
  end

  it "displays the Country drop down" do
    rendered.should contain("Country")
  end
end

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM