Я не хочу писать спецификацию для вида в Rails с Rspec. Я написал это:Модель-заглушка на вид
require 'spec_helper'
describe "homepage/index.html.erb" do
it 'has list of publications with id #publications' do
render
expect(rendered).to have_selector('ul#publications')
end
it 'has publications on the list' do
assign(:publications, [
stub_model(Publication, content: 'First publication.'),
stub_model(Publication, content: 'Second publication.')
])
render
rendered.should have_content('First publication.')
rendered.should have_content('Second publication.')
end
end
Но stub_model
, кажется, не работает.
rspec
.....F.
Failures:
1) homepage/index.html.erb has list of publications with id #publications
Failure/Error: render
ActionView::Template::Error:
undefined method `each' for nil:NilClass
# ./app/views/homepage/index.html.erb:2:in `_app_views_homepage_index_html_erb___3273264012123365698_43368240'
# ./spec/views/homepage/index.html.erb_spec.rb:5:in `block (2 levels) in <top (required)>'
Finished in 0.17634 seconds
7 examples, 1 failure
Как я могу заглушить это правильно?
Я downvoted ваш вопрос, потому что вы не предоставили соответствующий код вашего 'index.html.erb'. – phoet
Я думал, что это очевидно ... но в любом случае я спросил слишком быстро. Неудачный тест был первым, а не вторым. Поэтому я переместил назначение на 'before' и отлично работает. – ciembor