刚刚从 Cucumber+Webrat 切换到 Cucumber+Capybara,我想知道如何将内容 POST 到 Capybara 中的 URL。
在 Cucumber+Webrat 中我能够执行以下步骤:
When /^I send "([^\"]*)" to "([^\"]*)"$/ do |file, project|
proj = Project.find(:first, :conditions => "name='#{project}'")
f = File.new(File.join(::Rails.root.to_s, file))
visit "project/" + proj.id.to_s + "/upload",
:post, {:upload_path => File.join(::Rails.root.to_s, file)}
end
然而,Capybara 文档提到:
访问方法只需要一个
参数,请求方法为
总是得到。总是得到。
如何修改我的步骤,以便 Cucumber+Capybara 对 URL 执行 POST?
最近我发现这篇很棒的博文 http://suffix.be/blog/capybara-post-requests。这对于像托尼这样的情况非常有用,而且你真的可以want在你的 cuke 中发布一些内容:
对于我的情况,这变成了:
def send_log(file, project)
proj = Project.find(:first, :conditions => "name='#{project}'")
f = File.new(File.join(::Rails.root.to_s, file))
page.driver.post("projects/" + proj.id.to_s + "/log?upload_path=" + f.to_path)
page.driver.status_code.should eql 200
end
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)