我有一个运行 rspec-rails 2.14.0 的 rails 3.2.13 应用程序,并试图确认视图在我的测试中呈现了特定的部分。它确实有效,但我需要添加这个测试。这是我到目前为止所拥有的:
require 'spec_helper'
describe 'users/items/index.html.haml' do
let(:current_user) { mock_model(User) }
context 'when there are no items for this user' do
items = nil
it 'should render empty inventory partial' do
response.should render_template(:partial => "_empty_inventory")
end
end
end
这运行没有错误,但没有通过。失败是:
Failure/Error: response.should render_template(:partial => "_empty_inventory")
expecting partial <"_empty_inventory"> but action rendered <[]>
感谢您的任何想法。
编辑
这对我有用,但彼得的解决方案更好......
context 'when there are no items for this user' do
before do
view.stub(current_user: current_user)
items = nil
render
end
it 'should render empty inventory partial' do
view.should render_template(:partial => "_empty_inventory")
end
end
出于某种原因,不得不调用render
视图对我来说是违反直觉的,但是你去...