簡體   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