“未找到”使用 Capybara 测试omniauth Facebook 身份验证时

发布于 2024-10-27 10:21:36 字数 449 浏览 1 评论 0原文

我在我的项目中实现了 facebook Omniauth 身份验证系统。我在浏览器中工作得很好,直到今天我已经使用 Capybara 编写并通过了一整套集成测试。

但今天,我运行了测试套件,所有相关测试都失败了。

问题源于此帮助程序模块,该模块在几乎所有测试中都用于模拟 facebook(或其他)身份验证:

module IntegrationSpecHelper
  def login_with_oauth service
    visit "/auth/#{service}"
    save_and_open_page
  end
end

这似乎不再起作用,即使它在 2 天前起作用,并且仍然在我的开发服务器上起作用。 “save_and_open_page”显示的页面实际上包含“Not Found”行,仅包含其他内容。

有谁知道这会是什么原因造成的?

I have a facebook Omniauth authentication system implemented in my project. I works fine for me in the browser and up until today I had a full set of integration tests written and passing using Capybara.

Today though, I ran the test suite and all the related tests fail.

The problem stems from this helper module which is used in pretty much all the tests to simulate facebook (or otherwise) authentication:

module IntegrationSpecHelper
  def login_with_oauth service
    visit "/auth/#{service}"
    save_and_open_page
  end
end

This doesn't seem to work any more, even though it did 2 days ago, and still works on my development server. The "save_and_open_page" displays a page which literally contains the line "Not Found" and nothing else.

Anyone know what would cause this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

2024-11-03 10:21:36

最后我自己想出了这个办法。

基本上我是根据omniauth配置初始值设定项中的环境设置我的身份验证提供程序。我有这样的设置:

  if Rails.env.production?
    provider :facebook, ...
    provider :twitter, ...
  elsif Rails.env.development?
    provider :facebook, ...
    provider :twitter, ...
  end

如您所见,我忘记提供测试环境的设置,因此我的所有测试都失败了。

Figured this out myself in the end.

Basically I was setting my auth providers based on environment in my omniauth config initializer. I has this setup:

  if Rails.env.production?
    provider :facebook, ...
    provider :twitter, ...
  elsif Rails.env.development?
    provider :facebook, ...
    provider :twitter, ...
  end

As you can see I forgot to provide a settings for the test environment hence all my tests were failing.

雨后彩虹 2024-11-03 10:21:36

在rails 3中,您可以将每个omniauth配置初始值设定项放入config/environments文件夹中的相应环境文件中,即development.rb、test.rb和Production.rb

In rails 3, you can put each omniauth config initializer in the respective environment file in the config/environments folder i.e. development.rb, test.rb, and production.rb

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文