How do I check Omniauth with Rspec and Capybara?

Trying to test OmniAuth with RSpec and Capybara is completely unsuccessful.

So far, spec_helper.rb has:

 # Enable omniauth testing mode OmniAuth.config.test_mode = true OmniAuth.config.mock_auth[:google] = OmniAuth::AuthHash.new({ :provider => 'google', :uid => '1337', :info => { 'name' => 'JonnieHallman', 'email' => ' jon@test.com ' } }) 

And I know that I need to put Capybara tests under spec/features . Therefore, I have:

 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 end end 

But I get:

 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)>' 

Absolutely, completely lost. Went through the OmniAuth wiki and it really didn't help; searched for over an hour through Stack Overflow, no luck. Help?

+4
source share
1 answer

Having done quite a bit of reading, I finally managed to fix it. The test now reads as follows:

 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 end end 

Simple!

+4
source

All Articles