After following tutorials from internet of integration test of Google Login in Rails. I came to this. But it's not working.
# 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
I am supposing that after running the test my page content would change but they are same as before.