【发布时间】:2015-05-01 20:50:13
【问题描述】:
我正在尝试在 angular/rails 应用程序上使用 capybara 测试我的翻译。我在应用程序控制器中有一个 before 操作,它检查 url 中的子域并相应地设置语言环境。
为了在浏览器中手动测试,我必须修改我的 /hosts/etc 文件以包含我要测试的子域。该服务目前有效,但我想围绕它编写一个集成测试。
我发现了这个:http://www.chrisaitchison.com/2013/03/17/testing-subdomains-in-rails/,这似乎是一个可靠的解决方案,但它对我不起作用。每次我尝试运行测试时,I18n.locale 仍然设置为默认语言环境,而不是基于子域的语言环境。
有没有一种方法可以围绕这个编写集成测试,而不是让我期望页面有内容?我的测试目前看起来像:
context "no subdomain present", js: true do
it "sets the locale to the default when no valid subdomain is present" do
visit '/'
expect(I18n.locale).to eq(I18n.default_locale)
end
end
context "with a subdomain present", js: true do
it "sets the locale based on the subdomain" do
visit "hindi.127.0.0.1.xip.io:#{Capybara.server_port}/"
sleep(2)
expect(I18n.locale).to eq('hi')
end
end
顶部的测试当然通过了,但底部的测试没有。提前感谢,如果我忘记了什么,请告诉我,我会尽快添加。
【问题讨论】:
-
你试过
"http://hindi.127.0.0.1.xip.io:#{Capybara.server_port}/"吗? -
是的,我做到了,这导致了同样的错误。
标签: ruby-on-rails angularjs rspec internationalization capybara