我的 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
如果default_locale为“en”,则第一个测试通过,如果为“de”,则第二个测试通过。
路线和内容都没有被翻译(我使用 gem 'rails-translate-routes')。
最佳答案
也许这有帮助:
使用 capybara 时路径无法正常工作
对于 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
看here了解更多详情。
关于ruby-on-rails - 无法通过 :locale to Capybara's method visit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9564797/