For example, I have the following code:
context '#update_password' do
it 'current_user can update his password' do
user = FactoryBot.create :user
sign_in user
put :update_password, xhr: true, params: {
id: user.id,
user: {
id: user.id,
current_password: user.password,
password: 'ValidPass1!'
}
}
expect(response).to be_success
end
end
How can I write a rspec test to verify the recapcha validness on sign_in ?
PS I am using gem 'recaptcha', require: 'recaptcha/rails'
For me worked this:
context '#update_password' do
it 'current_user can update his password' do
user = FactoryBot.create :user
allow(controller).to receive(:verify_recaptcha).and_return(true)
sign_in user
put :update_password, xhr: true, params: {
id: user.id,
user: {
id: user.id,
current_password: user.password,
password: 'ValidPass1!'
}
}
expect(response).to be_success
end
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.