Stack level too high with `puts response` in rspec

Having a strange problem with rspec and rails in controller tests. Whenever we add puts response inside the specification, it outputs a lot 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 with SystemStackError: stack level too deep . Checking the answer through pry works fine, printing other materials also works great.

Upgrading to the latest version of rspec (2.11) does not matter. We noticed that puts calls the to_a answer on the answer that returns the array [@status, @header, self] , so for some reason does this cause this weird recursion?

update : here is a gist with code + spec

+4
source share
1 answer

I believe you encountered a rack error. [rack_response].flatten goes into an infinite loop. See these issues for more information:

The solution is to not set any expectations regarding the response object itself, instead set the expectations on the state, headers or body separately, for example:

 last_response.status.should eq(200) last_response.body.should include("some text") last_response.headers.should include("Content-Type" => "text/plain") 
+4
source

Source: https://habr.com/ru/post/1434823/


All Articles