timpone
timpone

Reputation: 19939

possible to access session variables in Rspec with Capybara

Is it possible to access session variables in Rspec with Capybara and Selenium drive?

How would I do something like this (I am using omniauth-facebook)?

require 'spec_helper'

describe 'Api' do
  def login_with_oauth
    visit "/auth/facebook"
  end

  it 'get location count for specific user' do
    login_with_oauth
    @user=User.find(session[:user_id])
    #puts "here is response body: #{response.body}"

I see How to inspect the session hash with Capybara and RSpec? but doesn't get me what I really want.

thx

Upvotes: 2

Views: 1214

Answers (1)

ck3g
ck3g

Reputation: 5929

I suppose to think what you actually don't need the session. I'm sorry if I'm wrong.

That's how you can test omniauth.

# spec/spec_helper.rb
OmniAuth.config.test_mode = true
OmniAuth.config.mock_auth[:facebook] = OmniAuth::AuthHash.new
OmniAuth.config.add_mock(:facebook, {
  provider: "facebook",
  uid: "123456",
  info: {
    email: "[email protected]",
    first_name: "Bruce",
    last_name: "Wayne"
  }
})


# spec/request/api_spec.rb
let!(:user) { create :user, email: "[email protected]" }

before do
  visit "/auth/facebook"
end

it 'get location count for specific user' do
  user.id # contains your user id
end

Upvotes: 1

Related Questions