【发布时间】:2014-03-15 14:59:03
【问题描述】:
我正在使用 Rspec 2 和 Rails 3.2。我想检查我的 rspec 测试是否在某些情况下呈现了特定文件。像这样:
it "should render mobile templates" do
get :index
response.should render_template(‘index.mobile.erb’)
response.should render_template(‘layout/application.mobile.erb’)
end
上面的 rspec 代码失败如下:
Failure/Error: response.should render_template('index.mobile.erb')
expecting <"index.mobile.erb"> but rendering with <"pages/index, layouts/application">
我在 Rspec 1.x 中读到了 was possible。但我无法使用 Rspec 2 和 rendered_template matcher 进行此检查。
附:我找到了 rails assertion assert_template 和它的 file 选项,但是这个选项被 rendered_template 忽略了。
UPD 如果我检查index.html.erb 而不是index.html.erb 会出现同样的错误
【问题讨论】:
标签: ruby-on-rails ruby layout rspec views