如何在 Sinatra 中使用 rspec 和rack-test 测试标头
因此,我有一个 Sinatra 应用程序,它通过 HTTP POST 从另一个服务接收 XML。我想在本地测试一下。我有一个发送到端点的测试 XML 文件。进展顺利。我还设置了一些如下标头:
post '/', xml, 'HTTP_X_MY_AWESOME_HEADER' => "It's value"
其中 xml
是发送到我的端点的普通 XML 的精确副本。但我作为参数传递的标头永远不会显示在输出中。
我在这里做错了什么吗? 这里有很多关于它的帖子,但都已经过时了。
我正在使用 Rspec 2.8、Sinatra 1.3.2、Ruby 1.9.3-p0、Rack::Test 0.6.1。
更新2012-01-28 11:37:显然我在问这个问题时没有思考。通过请求发送标头并不意味着我会在响应中收到它们。
所以现在的问题是:如何测试请求标头而不将它们与响应一起发送回来?
So I have a Sinatra app that receives an XML via a HTTP POST from another service. I want to test it locally. I have a test XML-file that I send to the endpoint. That goes well. I also set some headers like this:
post '/', xml, 'HTTP_X_MY_AWESOME_HEADER' => "It's value"
where xml
is the exact copy of normal XML that is being sent to my endpoint. But the header I pass as a parameter is never displayed in output.
Am I doing something wrong here?
There are a lot of posts around here about it, but all are outdated.
I'm using Rspec 2.8, Sinatra 1.3.2, Ruby 1.9.3-p0, Rack::Test 0.6.1.
UPDATE 2012-01-28 11:37: Obviously I was not thinking while I was asking this question. Sending headers with request does not mean I will receive them back in the response.
So the question now is: How do I test request headers without sending them back with the response?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该能够像这样检查last_request:
使用RSpec &您将使用上面的示例进行测试:
希望您能获得批准:)
更多信息请参见:
http://www.sinatrarb.com/testing.html#asserting_expectations_about_the_response
HTH
You should be able to inspect the last_request like so:
using RSpec & your example above you would test with:
And hopefully you'll get a green light :)
More info here:
http://www.sinatrarb.com/testing.html#asserting_expectations_about_the_response
HTH