This spec passes but fails after introducing locale (the application however works):
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
Then I add a scope to the routes to include the locale: ...
scope "/:locale" do
resources :products
root :to => 'products#index'
end
...
In application controller I define:
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
In the browser the app works again with paths like /en/product/1 to render the show template
But my test above fails with:
1) products/show renders name Failure/Error: render ActionView::Template::Error: No route matches {: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:in
block (2 levels) in '
Why does the test fail while the app works?
How do I make it pass?