gpt4 book ai didi

ruby - 为什么 'undefined method ` assert_equal' ' is thrown even after requiring ' test/unit'

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

我打开 irb 并输入:

require 'test/unit'

但是当我使用 assert_equal 方法时,出现以下错误:NoMethodError: undefined method 'assert_equal' for main:Object。为什么即使在需要“测试/单元”之后也会发生这种情况?

最佳答案

assert_equal 是在 Test::Unit::TestCase 的子类上定义的,因此仅在该类中可用。您可能会成功地使用 include Test::Unit::TestCase 将这些方法加载到当前范围。

更有可能的是,您最好将测试写在一个短文件中,然后使用 ruby ./my_file.rb 运行它们

关于ruby - 为什么 'undefined method ` assert_equal' ' is thrown even after requiring ' test/unit',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12317921/

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