uma*_*mar 22 integration-testing ruby-on-rails cucumber capybara
我正在使用Cucumber和Capybara.我需要发出HTTP DELETE
请求.以前使用webrat的功能,所以简单的声明就好
visit "/comment/" + comment_id, :delete
Run Code Online (Sandbox Code Playgroud)
工作,但现在我使用Capybara.
做一个GET
请求的方法很简单:
get 'path'
Run Code Online (Sandbox Code Playgroud)
并做一个帖子请求:
page.driver.post 'path'
Run Code Online (Sandbox Code Playgroud)
但是我如何模拟DELETE
请求呢?
我发现司机Capybara正在使用的是Capybara::RackTest::Driver
,如果有任何帮助的话.
我也尝试过:
Capybara.current_session.driver.delete "/comments/" + comment_id
Run Code Online (Sandbox Code Playgroud)
但这不起作用.
100*_*les 29
page.driver.submit :delete, "/comments/#{comment_id}", {}
Run Code Online (Sandbox Code Playgroud)
文档位于:http://rubydoc.info/gems/capybara/1.1.2/Capybara/RackTest/Browser : submit
如果您使用的驱动程序不支持自定义HTTP请求(例如Capybara-webkit,请参阅已关闭的问题和当前驱动程序),您可以临时切换到RackTest驱动程序以提交请求.
例如:
# Submit an HTTP delete request, using rack_test driver
def http_delete path
current_driver = Capybara.current_driver
Capybara.current_driver = :rack_test
page.driver.submit :delete, path, {}
Capybara.current_driver = current_driver
end
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7828 次 |
最近记录: |