开发者

"Not Found" when testing omniauth Facebook authentication with Capybara

开发者 https://www.devze.com 2023-02-21 02:50 出处:网络
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 Capyba

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开发者_如何学JAVA 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?


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消