开发者

Error when testing devise with omniauth and rspec

开发者 https://www.devze.com 2023-04-05 02:07 出处:网络
I wrote this simple spec : it \"redirects to dashboard upon login\" do user = Factory(:user) visit \"/users/sign_in

I wrote this simple spec :

  it "redirects to dashboard upon login" do
      user = Factory(:user)
      visit "/users/sign_in

why am I getting this error?

Failure/Error: visit "/users/sign_in"
ActionView::Template::Error:
undefined method `user_omniauth_authorize_path' for #<#<Class:0x00000102947cc8>:0x0000010293def8>

my spec_helper:

OmniA开发者_运维知识库uth.config.test_mode = true
OmniAuth.config.add_mock(:facebook, {:user_info => {:name => "Joe Smith", :nickname => 'joesmith'}, :uid => '123456790'})

and devise spec helper:

module DeviseSpecHelper
  RSpec.configure do |config|
    config.include Devise::TestHelpers, :type => :controller
  end

  def login_with_oauth(service = :facebook)
    visit "/auth/#{service}"
  end
end


I was getting that very same error this evening. In my config/initializers/devise.rb file I had twitter and facebook set up for both dev and production, but I didn't have anything for test. After setting up some rubbish data for the testing environment, everything worked.

This is what I'm using in my devise.rb initializer, with real keys removed.

if Rails.env.production?
  config.omniauth :twitter, '7630184729174927491732', 'asdfia8akfuoiafo8uasdfjad;lsfjalsf'
  config.omniauth :facebook, '4759010482048301849821', 'asdfawer82395ahusfi8afier98hakfdha'
else
  config.omniauth :twitter, '1231231231231231231231', 'slakjsdflakhsldiuvalejhiubsdlfkjhasdfjasdl'
  config.omniauth :facebook, '123123123123123', 's4s4aeraw4rert4f4awefa34afw4a4f3'
end
0

精彩评论

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