使用 Shoulda Ruby on Rails 获取 HTTP 响应
我正在从 rspec 迁移到 Shoulda,但似乎无法访问 http 响应。有人可以指出我可能做错了什么吗?
context "doing somethin" do
setup do
get :index
end
@response.body
should respond_with :success
end
当我运行此命令时,我收到一条错误消息,指出 @response 是一个空对象。
I'm migrating over to shoulda from rspec and I can't seem to get access to the http response. Can someone point out what I may be doing wrong?
context "doing somethin" do
setup do
get :index
end
@response.body
should respond_with :success
end
When i run this i get an error saying that @response is a nill object.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您想访问响应,您应该首先将其包装成“应该”,如下所示:
就像您尝试在测试之外使用响应一样,每个应该代表一个测试用例,而上下文就像是中的 before(:each)规格。
If you want to access the response you should first wrap into a "should" like this:
It's like you try to use the response outside a test, each should represents a test case, and a context is like a before(:each) in rspec.
我相信shoulda语法是:
should_respond_with:success
而不是:
should respond_with:success
I believe the shoulda syntax is:
should_respond_with :success
instead of:
should respond_with :success