![](/img/trans.png)
[英]Changing the value of a session variable in RSpec/Capybara/Selenium
[英]possible to access session variables in Rspec with Capybara
是否可以通過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}"
我看到如何使用Capybara和RSpec檢查會話哈希? 但沒有得到我真正想要的。
謝謝
我想想您實際上不需要會議。 如果我錯了,我很抱歉。
這樣便可以測試 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: "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.