4

Having a strange problem with rspec and rails in controller tests. Whenever we add puts response inside a spec, it outputs lots of these

200
{"Content-Type"=>"text/html; charset=utf-8"}
200
{"Content-Type"=>"text/html; charset=utf-8"}
200
{"Content-Type"=>"text/html; charset=utf-8"}
200
{"Content-Type"=>"text/html; charset=utf-8"}

and then fails with SystemStackError: stack level too deep. Inspecting the response via pry works great, printing other stuff also works fine.

Upgrading to latest rspec (2.11) does not make a difference. We noticed that the puts calls to_a on the response, which returns an array of [@status, @header, self], so somehow it causes this strange recursion?

update: here's a gist with the code + spec

4

1 回答 1

5

我相信您在机架中遇到了错误。 [rack_response].flatten进入无限循环。有关更多信息,请参阅这些问题:

解决方案是不对响应对象本身设置任何期望,而是分别对状态、标头或正文设置期望,例如:

last_response.status.should eq(200)
last_response.body.should include("some text")
last_response.headers.should include("Content-Type" => "text/plain")
于 2012-09-18T16:20:27.987 回答