【问题标题】:how do I use curl to test my Rails controller create action.. or can I use rspec?如何使用 curl 测试我的 Rails 控制器创建操作.. 或者我可以使用 rspec?
【发布时间】:2017-06-03 06:10:59
【问题描述】:

Rails 指南选择在其 API 部分中甚至不提及创建操作,请多多包涵。我的目标是构建一个可以从中创建内容的 RESTFUL API。这是$ curl myapp之后的表单样子

<form class="new_blog" id="new_blog" action="/blog" accept-charset="UTF-8" data-remote="true" method="post"><input name="utf8" type="hidden" value="&#x2713;" />
    <label for="blog_input">Input a String</label> 
    <textarea class="input-field" name="blog[input]" id="blog_input">
</textarea>
  <input type="submit" name="commit" value="Create Blog" />
</form>

我想通过 curl 发布内容...或者...我可以通过 Rspec 以某种方式对其进行测试吗?

目标是我有一个 RESTFUL API,它允许通过 HTTP 请求创建内容,然后给出 HTTP 响应。

【问题讨论】:

    标签: ruby-on-rails curl rspec


    【解决方案1】:

    您可以使用Ruby HTTP Cheat Sheet 直接从Ruby 创建各种类型的请求,无需为此使用curl。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多