Ruby on rails Can';t通行证:地点到水豚岛';s方法访问

Ruby on rails Can';t通行证:地点到水豚岛';s方法访问,ruby-on-rails,internationalization,capybara,Ruby On Rails,Internationalization,Capybara,我的Capybaras测试只适用于默认区域设置,而不适用于指定的区域设置 describe "How it works" do it "should have the content 'how it works'" do visit how_it_works_url(:locale => :en) page.should have_content('How it works') end it "should have the content 'wie

我的Capybaras测试只适用于默认区域设置,而不适用于指定的区域设置

describe "How it works" do
  it "should have the content 'how it works'" do
    visit how_it_works_url(:locale => :en)
    page.should have_content('How it works')      
  end
  it "should have the content 'wie es geht'" do
    visit how_it_works_url(:locale => :de)
    page.should have_content('Wie es geht')      
  end
end  
如果默认语言环境为“en”,则第一个测试通过,如果为“de”,则第二个测试通过

既不翻译路线(我使用gem“rails translate routes”),也不翻译内容。

这可能有助于:

使用时路径工作不正常

对于rspec,您可以将此代码段放在
spec/support/locale.rb中,例如:

# workaround, to set default locale for ALL spec
class ActionView::TestCase::TestController
  def default_url_options(options={})
    { :locale => I18n.default_locale }
  end
end

class ActionDispatch::Routing::RouteSet
  def default_url_options(options={})
    { :locale => I18n.default_locale }
  end
end
寻找更多细节