Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby Mocha Unittest can';“找不到”;有“U键”;方法_Ruby_Unit Testing_Ruby Mocha - Fatal编程技术网

Ruby Mocha Unittest can';“找不到”;有“U键”;方法

Ruby Mocha Unittest can';“找不到”;有“U键”;方法,ruby,unit-testing,ruby-mocha,Ruby,Unit Testing,Ruby Mocha,我已经使用test::Unit和Mocha编写了一个单元测试。我正在使用“expects”模拟我正在测试的类中的一个方法,我想检查某个参数是否传递到对象中: service.expects(:get).once.with(path, has_key('t')).returns([]) 在我的开发系统上,这运行得很好。在我同事的计算机上以及Travis CI服务器上,单元测试失败,出现以下错误: NoMethodError: undefined method `has_key' for #<

我已经使用test::Unit和Mocha编写了一个单元测试。我正在使用“expects”模拟我正在测试的类中的一个方法,我想检查某个参数是否传递到对象中:

service.expects(:get).once.with(path, has_key('t')).returns([])
在我的开发系统上,这运行得很好。在我同事的计算机上以及Travis CI服务器上,单元测试失败,出现以下错误:

NoMethodError: undefined method `has_key' for #<FloxTest:0x000000036d4770>
如果任何人需要更多的上下文,完整的测试文件是。事实上,整个项目是开源的,它是一个相当小的项目:; 可以在上查看完整的错误日志

我对我能尝试什么没有更多的想法。我们甚至确保我的同事拥有与我完全相同的gem版本;Ruby版本也是一样的

提前感谢Ruby大师的帮助,我非常感谢

我现在代表您添加了这个


您可以在中查看我建议的修复。我希望这能有所帮助。

的确,效果非常好,非常感谢!供参考/其他读者:我将“摩卡/测试单元”与“摩卡/设置”交换。问题的原因是“Test::Unit”的标准库版本在内部使用了“MiniTest”,因此“MiniTest”需要由Mocha操作。@JamesMead为什么不在这里的答案中包含修复程序,因为只有链接的答案用途有限(因此,通常被认为是堆栈溢出时的非答案)。
require 'test/unit'
require 'mocha/test_unit'