问题描述
我打开了 irb &输入:
I opened irb & entered:
require 'test/unit'
但是当我使用 assert_equal
方法时,出现以下错误:NoMethodError: undefined method 'assert_equal' for main:Object
.为什么即使在要求测试/单元"之后也会发生这种情况?
but when I used the assert_equal
method, I got following error: NoMethodError: undefined method 'assert_equal' for main:Object
. Why is this happening even after requiring 'test/unit' ?
推荐答案
assert_equal
定义在 Test::Unit::TestCase
的子类上,因此仅在那个班.您可能会成功使用 include Test::Unit::TestCase
将这些方法加载到当前范围.
assert_equal
is defined on subclasses of Test::Unit::TestCase
, so are only available in that class. You may have some success with include Test::Unit::TestCase
to load those methods onto the current scope.
更有可能将测试编写在一个短文件中,并使用 ruby ./my_file.rb
More likely you could be better writing your tests in a short file, and running them with ruby ./my_file.rb
这篇关于为什么即使在需要“测试/单元"之后也会抛出“未定义的方法‘assert_equal’"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!