gpt4 book ai didi

ruby-on-rails - rspec 输出中的 rails omniauth 错误

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

我有一个使用 devise/omniauth 允许通过 facebook 登录的 Rails 4 应用程序。该应用程序似乎有效,测试似乎也有效。但是我有一个测试来检查用户通过 facebook 登录但决定不授予权限的情况。

此测试工作正常,但会向 rspec 输出发送一条错误消息

$ rspec -fd --tag inspect 
Sign in with facebook
new user
E, [2013-10-20T21:25:24.232573 #17137] ERROR -- omniauth: (facebook) Authentication failure! invalid_credentials encountered
does not grant permission

Finished in 0.21152 seconds
1 example, 0 failures

Randomised with seed 52495

$ rspec 
....E, [2013-10-20T21:25:24.232573 #17137] ERROR -- omniauth: (facebook) Authentication failure! invalid_credentials encountered.
............................................................

Finished in 0.95531 seconds
74 examples, 0 failures

Randomized with seed 2946

相关测试

require 'spec_helper.rb'

feature "sign in with facebook" do
context "new user" do
scenario "does not grant permission", inspect: true do
dont_sign_in_with_facebook
expect(notice_area).to have_content "Could not authenticate you from Facebook because \"Invalid credentials\""
end
end
end

和 authentication_helper

module Features
module AuthenticationHelpers
def dont_sign_in_with_facebook
OmniAuth.config.test_mode = true
OmniAuth.config.mock_auth[:facebook] = :invalid_credentials
visit "/users/auth/facebook"
end
end
end

我可以做些什么来抑制 rspec 输出中的错误消息吗?

编辑

我尝试实现@Shepmaster 描述的静音功能,但没有解决问题。然后尝试从 rspec 命令重定向错误:

rspec -fd --tag inspect  2> /dev/null
Sign in with facebook
new user
E, [2013-10-20T21:25:24.232573 #17137] ERROR -- omniauth: (facebook) Authentication failure! invalid_credentials encounterd
does not grant permission

Finished in 0.21152 seconds
1 example, 0 failures

Randomised with seed 65190

并重定向标准输出

rspec -fd --tag inspect  > /dev/null

没有输出!

最后使用输出选项

rspec -fd --tag inspect -o /tmp/rspec.out 2> /dev/null
cat /tmp/rspec.out

Sign in with facebook
new user
does not grant permission

Finished in 0.21152 seconds
1 example, 0 failures

Randomised with seed 65190

回答使用@shepmaster 的答案

module Features
module AuthenticationHelpers
def dont_sign_in_with_facebook
OmniAuth.config.test_mode = true
OmniAuth.config.mock_auth[:facebook] = :invalid_credentials
silence_omniauth {visit "/users/auth/facebook"}
end
end
end

最佳答案

我在 Rails 4.2 应用程序中遇到了同样的问题。解决方法是在初始化程序中将 OmniAuth 记录器设置为 Rails 记录器 per the README :

# config/initializers/omniauth.rb
OmniAuth.config.logger = Rails.logger

关于ruby-on-rails - rspec 输出中的 rails omniauth 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19483367/

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