我在一个 Action 中有以下代码:
render :file => 'public/404.html' and return
这在浏览器中运行良好。我编写了以下 rspec 示例来对此进行测试:
it "renders 404" do
get :new
response.should render_template('public/404.html')
end
运行此示例会导致以下错误:
Failure/Error: response.should render_template('public/404.html')
Expected block to return true value.
我也尝试过 response.should render_template(:file => 'public/404.html')
但这也会导致错误。
我应该如何测试它?
最佳答案
你应该使用:
response.should render_template(:file => "#{Rails.root}/public/404.html")
关于ruby-on-rails - 如何测试渲染 :file => 'public/404.html' in Rspec 2?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11450692/