到目前为止,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?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)