Rails/Cucumber - 托管错误测试omniauth(提供者:facebook) - (URI::InvalidComponentError)
我在尝试配置omniauth以进行与cucumber的集成测试时遇到错误(我按照wiki提供的方式通过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.featureomniauth_steps.rb
Feature: OmniAuth
Scenario: Test
Given I am signed in with facebook
Then I open the page
env.rbinitializer
Given /^I am signed in with facebook$/ do
visit "/auth/facebook"
end
support/
OmniAuth.config.test_mode = true
OmniAuth.config.mock_auth[:facebook] = {
'uid' => '12345',
"user_info" => {
"email" => "[email protected]",
"first_name" => "foo",
"last_name" => "Bar"
}
}
/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:< a href="http://example.com/">http://example.com/
我很高兴知道是否有人有这样的想法/经历过。 谢谢你!
I am facing an error trying to configure omniauth for integration testing purpose with cucumber (I set up Omniauth through Devise as the wiki provides)
Please see below:
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
Here are my files:
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
support/env.rb
OmniAuth.config.test_mode = true
OmniAuth.config.mock_auth[:facebook] = {
'uid' => '12345',
"user_info" => {
"email" => "[email protected]",
"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
(Reference: issue 257)
routes
devise_scope :user do
get '/auth/:provider' => 'users/omniauth_callbacks#passthru'
end
devise_for :users, :path => "", :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
As info, I also configured my facebook test_app with the following URL: http://example.com/
I would be pleased to know if someone has a thought/experienced this.
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试将 : 添加
注释掉 : 。
到您的 support/env.rb 文件中,也尝试从您的初始化程序/devise.rb 文件中
try to add :
to your support/env.rb file, try also commenting out :
from your initializer/devise.rb file.
也许我在这里假设的太少,但以防万一..您是否设置了身份验证控制器和关联的路由?
编辑:抱歉,我刚刚意识到您说您按照维基提供的方式设置了所有内容。我猜你已经这样做了。我想无论如何我都会把它留在这里。
要了解如何设置身份验证控制器,您应该观看 Ryan Bates 截屏视频 关于这个主题。他们确实是一个极好的资源。
我有一个用完整的 Facebook 身份验证编写的控制器,如果您愿意,我可以发布它?请发表评论。
Perhaps I'm assuming too little here but just in case.. have you set up an authentications controller and associated routing?
Edit: Sorry I just realised you said you set everything up as the wiki provides. I guess you've done this so. I guess I'll leave it here anyway.
To learn about how to set up the Authentication Controller you should watch Ryan Bates screencasts on the subject. They are really an excellent resource.
I have a controller written with full facebook authentication that I can post if you like? Just leave a comment.