1

私のビュー仕様では、次のものがあります

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

ページに実際にテキストが含まれているのに、なぜこのエラーが発生するのか混乱しています。

4

1 に答える 1

2

操作するためにインスタンス変数が必要ですか? つまり、コントローラーのインデックスメソッドで設定されたものは何でも...次のようなものです:

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
于 2013-11-07T10:54:26.913 に答える