Fil*_*uzi 5 testing rspec ruby-on-rails vcr ruby-on-rails-4
我想使用的一些第三方服务要求用户登录其网页。方便的 url 在下面的控制器中生成。用户去那里并在身份验证成功后返回我的服务
class MyController < App::BaseController
def login
redirect_to SOME_API.external_url(ENV['secret_id'])
end
end
Run Code Online (Sandbox Code Playgroud)
当用户返回我的服务时,他会在 URL 参数中带来一些来自第三方服务的反馈(例如:)myapp.com/login_callack?response=error&reason=wrong_password。这些参数有很多变体,因此我需要在操作中处理它们
def login_callback
#SOME MAGIC WITH COOKIES/ERRORS/What ever
redirect_to root_path
end
Run Code Online (Sandbox Code Playgroud)
我想使用 RSpec 和 capybara 为其编写功能规范。
scenario 'User authenticates with third-party thing' do
visit '/anything'
click_link 'Go to MyController#login and than get redirect to somerandom.url/login_logic'
# use cassette below
fill_out_form
click_button confirm
# magic happens on their side and their redirect user to my app into #login_callback action
expect(page).to have(/all fancy things i need/)
end
end
Run Code Online (Sandbox Code Playgroud)
然而,调用WebMock.disable_net_connect!(allow_localhost: true)或添加并vcr: { cassette_name: 'using_third_party_login', record: :new_episodes }不能阻止这种情况被重定向到外部 url。
Capybara 只是让被重定向到外部 uri,并且没有录制/播放任何磁带。知道如何redirect_to external_url用盒式磁带播放/录音进行存根吗?
| 归档时间: |
|
| 查看次数: |
479 次 |
| 最近记录: |