如何POST到水豚的网址? [英] How do you POST to a URL in Capybara?

查看:119
本文介绍了如何POST到水豚的网址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚刚从Cucumber + Webrat切换到Cucumber + Capybara,我想知道如何将内容发布到Capybara的网址。

Just switched from Cucumber+Webrat to Cucumber+Capybara and I am wondering how you can POST content to a URL in Capybara.

在Cucumber + Webrat有一个步骤:

In Cucumber+Webrat I was able to have a step:

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文档提到:

However, the Capybara documentation mentions:


visit方法只需要一个
参数,请求方法是
GET.always GET。

The visit method only takes a single parameter, the request method is always GET.always GET.

如何修改步骤,使Cucumber + Capybara对URL进行POST?

How do I modify my step so that Cucumber+Capybara does a POST to the URL?

推荐答案

最近,我发现了这个优秀的博客帖子。这对于像Tony这样的情况和你真正想要在你的cuke中发布内容的情况非常有用:

More recently I found this great blog post. Which is great for the cases like Tony and where you really want to post something in your cuke:

对于我的情况,这变成了: p>

For my case this became:

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

这篇关于如何POST到水豚的网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆