开发者

How to assert the content of the response body in rails 3 functional test

开发者 https://www.devze.com 2023-03-10 16:26 出处:网络
I have a Rails 3.0.7 application. In the functional test I have following code. I am not using rspec or anything. This is plain vanilla functional test that comes with ra开发者_运维问答ils.

I have a Rails 3.0.7 application. In the functional test I have following code. I am not using rspec or anything. This is plain vanilla functional test that comes with ra开发者_运维问答ils.

assert_response :success

Above assertion is passing. However I need to assert on the full content that is returned as the body of the response. How do I access the response body?


You can access the response body in a functional test via:

response.body

Often, in this style of testing, you really want to use the method:

assert_select

A nice way to check out the assert_select API is via the cheat gem:

gem install cheat
cheat assert_select


This rails testing guide might help you some: http://guides.rubyonrails.org/testing.html#testing-views

0

精彩评论

暂无评论...
验证码 换一张
取 消