gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 05:25:49 25 4
gpt4 key购买 nike

我在尝试配置 omniauth 以使用 cucumber 进行集成测试时遇到错误(我通过维基提供的 Devise 设置了 Omniauth)

请看下面:

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

这是我的文件:

omniauth.feature

Feature: OmniAuth

Scenario: Test
Given I am signed in with facebook
Then I open the page

omniauth_steps.rb

Given /^I am signed in with facebook$/ do
visit "/auth/facebook"
end

支持/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"
}
}

initializer/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

(引用:issue 257)

路线

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

devise_for :users, :path => "", :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }

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

我很高兴知道是否有人对此有想法/经历过。谢谢!

最佳答案

尝试添加:

Before do
Capybara.default_host = 'example.com'
end

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

OmniAuth.config.full_host = 'http://example.com' # issue 257

来自您的 initializer/devise.rb 文件。

关于ruby-on-rails - Rails/Cucumber - 托管错误测试 omniauth(提供者:facebook) - (URI::InvalidComponentError),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6084066/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com