gpt4 book ai didi

ruby - 在 Ruby 中使用断言但不作为单元测试的一部分的最佳实践是什么?

转载 作者:数据小太阳 更新时间:2023-10-29 07:45:35 24 4
gpt4 key购买 nike

我想使用断言在 r​​ake 任务中引发错误。

the_index = items.index(some_item)
assert_not_nil the_index, "Lookup failed for the following item: " + some_item

我得到 undefined method assert_not_nil。我可以在我的 rake 任务中包含断言文件吗?怎么办?

这是最佳实践,还是有更好的方法?

使用 Ruby 1.9.2。

最佳答案

实际上,您可以在任何需要的地方使用断言。

require "minitest/unit"
include MiniTest::Assertions # all assertions are in this module
refute_nil @ivar, "An instance variable should not be nil here!"

但是你为什么要这么做?而是自己提出有意义的异常。

关于ruby - 在 Ruby 中使用断言但不作为单元测试的一部分的最佳实践是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8513645/

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