ruby-on-rails – 我应该如何使用Rspec和Capybara测试Omniauth?

ruby-on-rails – 我应该如何使用Rspec和Capybara测试Omniauth?,第1张

概述试图用RSpec和Capybara测试OmniAuth,完全失败了. 到目前为止,spec_helper.rb有: # Enable omniauth testing modeOmniAuth.config.test_mode = trueOmniAuth.config.mock_auth[:google] = OmniAuth::AuthHash.new({ 试图用RSpec和Capybara测试OmniAuth,完全失败了.

到目前为止,spec_helper.rb有:

# Enable omniauth testing modeOmniAuth.config.test_mode = trueOmniAuth.config.mock_auth[:Google] = OmniAuth::AuthHash.new({                                                            :provIDer => 'Google',:uID => '1337',:info => {                                                                'name' => 'JonnIEHallman','email' => '[email protected]'                                                            }                                                        })

而且我知道我需要将Capybara测试置于规格/功能之下.所以我有:

require 'spec_helper'describe "Authentications" do  context "without signing into app" do    it "sign in button should lead to Google authentication page" do      visit root_path      click_link "Login"      Authentication.last.uID.should == '1337'    end  endend

但我得到:

1) Authentications without signing into app sign in button should lead to Google authentication page Failure/Error: Authentication.last.uID.should == '1337' nameError:   uninitialized constant Authentication # ./spec/features/omniauth_spec.rb:10:in `block (3 levels) in <top (required)>'

完全失败了.通过OmniAuth wiki,它真的没有帮助;通过Stack Overflow搜索了一个多小时,没有运气.救命?

解决方法 在做了很多阅读之后,我终于设法解决了这个问题.测试现在看起来像这样:

require 'spec_helper'describe "Authentications" do  context "Clicking the login link" do    it "Login button should log in" do      visit root_path      click_link "Login"      page.should have_link "logout"    end  endend

简单!

总结

以上是内存溢出为你收集整理的ruby-on-rails – 我应该如何使用Rspec和Capybara测试Omniauth?全部内容,希望文章能够帮你解决ruby-on-rails – 我应该如何使用Rspec和Capybara测试Omniauth?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1279532.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-09
下一篇 2022-06-09

发表评论

登录后才能评论

评论列表(0条)

保存