【问题标题】:possible to access session variables in Rspec with Capybara可以使用 Capybara 访问 Rspec 中的会话变量
【发布时间】:2012-08-28 21:46:19
【问题描述】:

是否可以使用 Capybara 和 Selenium 驱动器访问 Rspec 中的会话变量?

我将如何做这样的事情(我正在使用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}"

我明白了 How to inspect the session hash with Capybara and RSpec? 但没有得到我真正想要的。

谢谢

【问题讨论】:

    标签: ruby-on-rails rspec capybara


    【解决方案1】:

    我想想想你实际上不需要会话。如果我错了,我很抱歉。

    那是how you can testomniauth。

    # 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-21
      • 2023-03-13
      • 2012-07-28
      • 2011-10-23
      相关资源
      最近更新 更多