简体   繁体   English

可以使用Capybara在Rspec中访问会话变量

[英]possible to access session variables in Rspec with Capybara

Is it possible to access session variables in Rspec with Capybara and Selenium drive? 是否可以通过Capybara和Selenium驱动器访问Rspec中的会话变量?

How would I do something like this (I am using omniauth-facebook)? 我将如何做这样的事情(我正在使用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? 我看到如何使用Capybara和RSpec检查会话哈希? but doesn't get me what I really want. 但没有得到我真正想要的。

thx 谢谢

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. 这样便可以测试 omn​​iauth。

# 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: "bruce.wayne@batman.com",
    first_name: "Bruce",
    last_name: "Wayne"
  }
})


# spec/request/api_spec.rb
let!(:user) { create :user, email: "bruce.wayne@batman.com" }

before do
  visit "/auth/facebook"
end

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM