ruby-on-rails - Omniauth 模拟在 rails rspec 中不起作用。谷歌登录按钮没有被点击
问题描述
在遵循 Google Login in Rails 的集成测试互联网教程之后。我来到这里。但它不起作用。
# frozen_string_literal: true
require "rails_helper"
def stub_omniauth
OmniAuth.config.test_mode = true
OmniAuth.config.mock_auth[:google_oauth2] = OmniAuth::AuthHash.new({
provider: "google_oauth2",
uid: "12345678910",
info: {
email: "limsammy1@gmail.com",
first_name: "Sam",
last_name: "Lim"
},
credentials: {
token: "abcdefg12345",
refresh_token: "abcdefg12345",
expires_at: DateTime.now,
}
})
end
RSpec.feature "user logs in" do
scenario "using google oauth2" do
visit login_path
stub_omniauth
Rails.application.env_config["omniauth.auth"] = OmniAuth.config.mock_auth[:google_oauth2]
expect(page).to have_css("a.google-login-button")
find("a.google-login-button").click
expect(page.current_path).to eq(dashboard_path)
end
end
我假设在运行测试后我的页面内容会改变,但它们和以前一样。
解决方案
推荐阅读
- php - 为什么没有正确添加价值?
- javascript - React.js 应用程序在服务器中作为空白页面打开,而在本地运行良好
- python - 使用多行字符串执行查询
- python - Create process in python, only if it doesn't exist
- php - PHP fgetcsv 失败,而爆炸工作正常
- amp-html - AMP 状态不适用于 AMP.navigateTo()
- r - 在 mutate dplyr 中使用逻辑运算符
- ms-access - Textbox with reference to dropdown returns nothing
- python - 如何在 Python dict 中的值之前附加一个键?
- mysql - MySQL 需要 6 秒来计算 100k 条记录中的条件