【发布时间】:2013-06-24 01:25:54
【问题描述】:
此规范通过但在引入语言环境后失败(但该应用程序有效):
require 'spec_helper'
describe "products/show" do
before do
assign(:product, mock_model("Product", name: "Car", description: "petrol engine"))
end
it "renders name" do
render
expect(rendered).to match /Car/
end
end
然后我在路由中添加一个范围以包含语言环境: ...
scope "/:locale" do
resources :products
root :to => 'products#index'
end
...
在应用程序控制器中我定义:
def self.default_url_options(options={})
logger.debug "default_url_options is passed options: #{options.inspect}\n"
I18n.locale = 'en' # fixed for tests
{ :locale => I18n.locale}
end
在浏览器中,应用程序再次使用路径,如 /zh/product/1 渲染显示模板
但是我上面的测试失败了:
1) 产品/节目呈现名称 失败/错误:渲染 动作视图::模板::错误: 没有路线匹配 {:action=>"edit", :controller=>"products", :locale=>#} # ./app/views/products/show.html.erb:14:in
_app_views_products_show_html_erb__333746538_80999240' # ./spec/views/products/show.html.erb_spec.rb:10:inblock (2 个级别) in '
为什么应用运行时测试失败?
如何让它通过?
【问题讨论】:
-
rspec 似乎不支持 default_url_options。见github.com/rspec/rspec-rails/issues/255
标签: locale rspec-rails