Rails/Cucumber - 托管错误测试omniauth(提供者:facebook) - (URI :: InvalidComponentError)

ben*_*itr 5 facebook ruby-on-rails cucumber devise omniauth

我正面临一个错误,试图配置omniauth用于黄瓜的集成测试目的(我通过Devise设置Omniauth,因为wiki提供)

请看下面:

Scenario: Test                       # features/omniauth.feature:3
  Given I am signed in with facebook # features/step_definitions/omniauth_steps.rb:1
    bad component(expected host component): http://www.example.com (URI::InvalidComponentError)
    /Users/benoit/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/uri/generic.rb:395:in `check_host'
    /Users/benoit/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/uri/generic.rb:409:in `host='
    ./features/step_definitions/omniauth_steps.rb:2:in `/^I am signed in with facebook$/'
    features/omniauth.feature:4:in `Given I am signed in with facebook'
  Then I open the page               # features/step_definitions/debug_steps.rb:5
Run Code Online (Sandbox Code Playgroud)

这是我的文件:

omn​​iauth.feature

Feature: OmniAuth

  Scenario: Test
    Given I am signed in with facebook
    Then I open the page
Run Code Online (Sandbox Code Playgroud)

omn​​iauth_steps.rb

Given /^I am signed in with facebook$/ do
  visit "/auth/facebook"
end
Run Code Online (Sandbox Code Playgroud)

支持/ env.rb

OmniAuth.config.test_mode = true
OmniAuth.config.mock_auth[:facebook] = {
  'uid' => '12345',
  "user_info" => {
    "email" => "foobar@example.com",
    "first_name" => "foo",
    "last_name" => "Bar"
  }
}
Run Code Online (Sandbox Code Playgroud)

初始化/ devise.rb

case 
  when Rails.env.production?
    config.omniauth :facebook, 'XXXX', 'XXXX', 
    {:scope => 'email, offline_access', :client_options => {:ssl => {:ca_file => '/usr/lib/ssl/certs/ca-certificates.crt'}}}
  when Rails.env.development?
    config.omniauth :facebook, 'XXXX', 'XXXX'
  when Rails.env.test?
    config.omniauth :facebook, 'XXXX', 'XXXX'
        OmniAuth.config.full_host = 'http://example.com' # issue 257  
end
Run Code Online (Sandbox Code Playgroud)

(参考:第257期)

路线

devise_scope :user do 
  get '/auth/:provider' => 'users/omniauth_callbacks#passthru'
end

devise_for :users, :path => "", :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
Run Code Online (Sandbox Code Playgroud)

作为信息,我还使用以下URL配置了我的facebook test_app:http://example.com/

我很高兴知道是否有人有这样的想法/经验.谢谢!

BBJ*_*BJ3 1

尝试添加:

Before do
  Capybara.default_host = 'example.com'
end
Run Code Online (Sandbox Code Playgroud)

在您的 support/env.rb 文件中,也尝试注释掉:

OmniAuth.config.full_host = 'http://example.com' # issue 257
Run Code Online (Sandbox Code Playgroud)

来自您的初始化程序/devise.rb 文件。