我有一个示例项目,用户可以使用他们的Google帐户登录,现在我想编写测试来验证用户是否已成功使用他的Google登录帐户。但我不知道如何在我的测试文件中验证这个东西? 这就是我现在尝试但它无法正常工作
OmniAuth.config.mock_auth[:google] = OmniAuth::AuthHash.new({
:provider => 'google',
:uid => '1337',
:info => {
'name' => 'JonnieHallman',
'email' => 'jon@test.com'
}
request.env["devise.mapping"] = Devise.mappings[:user]
request.env["omniauth.auth"] = OmniAuth.config.mock_auth[:google]
我认为在此之后我的页面内容会发生变化,但它们与以前相同
答案 0 :(得分:1)
您可以按照有关如何使用Omniauth https://github.com/intridea/omniauth/wiki/Integration-Testing
进行集成测试的指南进行操作基本上你的spec/rails_helper.rb
OmniAuth.config.test_mode = true
OmniAuth.config.mock_auth[:xing] = OmniAuth::AuthHash.new({
:provider => 'google',
:uid => '123545',
:info => {
:name => "Test",
:email => "test@test.com"
},
:credentials => {
:token => "token",
:secret => "secret"
}
# etc.
})
然后让login_helper
执行类似
def login
Rails.application.env_config["omniauth.auth"] = OmniAuth.config.mock_auth[:google]
visit root_path
click_link 'loginBtn'
end