开发者

Why was assert_template deprecated, and what should I use instead?

开发者 https://www.devze.com 2023-01-18 10:07 出处:网络
According to the doc开发者_运维问答umentation for assert_template, it\'s deprecated.Why was it deprecated, and what should I use instead?Disclaimer: I\'m aware that this is pretty old question, but wi

According to the doc开发者_运维问答umentation for assert_template, it's deprecated. Why was it deprecated, and what should I use instead?


Disclaimer: I'm aware that this is pretty old question, but will answer it anyway.

Reasoning:

The idea behind the removal of these methods is that instance variables and which template is rendered in a controller action are internals of a controller, and controller tests should not care about them. According to Rails team, controller tests should be more concerned about what is the result of that controller action like what cookies are set, or what HTTP code is set rather than testing of the internals of the controller. So, these methods are removed from the core.

Proposed solution:

assert_response :success

# or rspec with should
response.should be_success

# or rspec with expect
expect(response).to have_http_status(:success)

Github Issue and explanation from DHH himself


I don't know why api doc says it is deprecated, it still lives in 2.3.8 documentation, but in another file: http://railsapi.com/doc/rails-v2.3.8/classes/ActionController/Assertions/ResponseAssertions.html#M001705

0

精彩评论

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