gpt4 book ai didi

ruby-on-rails - 为什么不推荐使用 assert_template,我应该改用什么?

转载 作者:行者123 更新时间:2023-12-04 06:44:53 25 4
gpt4 key购买 nike

根据 the documentation for assert_template ,已弃用。为什么它被弃用了,我应该用什么来代替?

最佳答案

免责声明:我知道这是一个很老的问题,但无论如何都会回答。

推理:

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.



建议的解决方案:
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

关于ruby-on-rails - 为什么不推荐使用 assert_template,我应该改用什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3853584/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com