ruby-on-rails – 如何使用Minitest存根设置方法?
发布时间:2020-12-17 02:26:07 所属栏目:百科 来源:网络整理
导读:如何在设置中使用存根方法? 我只发现了这样的存根: class FooTest ActiveSupport::TestCase test 'for_something' do Foo.stub :some_method,3 do #assert_equal end end end 但是我希望对所有测试都存根.我该如何存根? 解决方法 您可以通过覆盖测试用例
如何在设置中使用存根方法?
我只发现了这样的存根: class FooTest < ActiveSupport::TestCase test 'for_something' do Foo.stub :some_method,3 do #assert_equal end end end 但是我希望对所有测试都存根.我该如何存根? 解决方法
您可以通过覆盖测试用例中的#run方法来实现:
class FooTest < ActiveSupport::TestCase def run Foo.stub :some_method,3 do super end end test 'for_something' do #assert_equal end end 这是引入需要在每个测试用例“周围”执行的代码的常用方法. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |