我正在运行 Ruby 1.9.3 和 Rails 3.1。我可以通过向自己发送 XML 有效负载来成功地手动测试我对 Washout gem 的使用。我正在尝试在 rails 测试中重新创建以下 bash 命令:
curl -H "Content-Type: text/xml; charset=utf-8" -H "SOAPAction:soap_submit_contract" -d@test/fixtures/soap/success.xml http://localhost/soap/action
如您所见,它设置了一些头数据并发送文件中的数据test/fixtures/soap/success.xml
我看到的所有其他 POST 示例如下所示:
post :parse_pdf,
:terminal_key => @terminal_key,
:contract_pdf => load_pdf(pdf)
但在我的情况下,文件数据不是命名参数,这似乎不是设置标题信息。
如何以与 curl 命令完全相同的方式提交帖子?
我们的测试套件使用默认的 ActionController::TestCase,如下所示:
class SoapControllerTest < ActionController::TestCase
fixtures :terminals
test "soap_succeeds" do
# request.set_header_information ???
post :action, # file data ???
assert_match(/success/, @response.body)
end
end