Angular / Rails应用程序中子域的集成测试I18n

时间:2015-05-01 20:50:13

标签: ruby-on-rails angularjs rspec internationalization capybara

我正试图在角度/ 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

当然最高的测试通过,但是底部测试没有。在此先感谢,如果我忘了什么,请告诉我,我会尽快添加。

0 个答案:

没有答案