Testing Rails Mocha gem-NoMethodError:未定义的方法'any#u instance';
我在一个Rails项目中使用MochaGem来生成存根并绕过一些实时API调用 我符合标准,但不断出现错误 在Testing Rails Mocha gem-NoMethodError:未定义的方法'any#u instance';,testing,ruby-on-rails-4,mocha.js,Testing,Ruby On Rails 4,Mocha.js,我在一个Rails项目中使用MochaGem来生成存根并绕过一些实时API调用 我符合标准,但不断出现错误 在Gemfile(我使用Bundler)中,我有: 在test\u helper.rb中: require 'minitest' require 'mocha/mini_test' # This is the last require statement require 'test_helper' class ProductControllerTest < ActionContr
Gemfile
(我使用Bundler)中,我有:
在test\u helper.rb
中:
require 'minitest'
require 'mocha/mini_test' # This is the last require statement
require 'test_helper'
class ProductControllerTest < ActionController::TestCase
setup do
Product.any_instance.stubs({
manufacturer: "Acme"
})
end
end
在product\u controller\u test.rb
中:
require 'minitest'
require 'mocha/mini_test' # This is the last require statement
require 'test_helper'
class ProductControllerTest < ActionController::TestCase
setup do
Product.any_instance.stubs({
manufacturer: "Acme"
})
end
end
需要“测试助手”
类ProductControllerTest
输出始终是#的未定义方法“any_instance”
我有另一个Rails项目,在那里我可以成功地使用any_实例
,因此我尝试通过复制gems、require
语句等来解决问题,但没有成功。我还尝试了不同的排列方式,如要求“迷你测试/自动运行”
,要求“迷你测试/轨道”
,要求“摩卡/设置”
/要求“摩卡”
,等等
我使用的是Rails 4.1.1,使用的是MiniTest 5.3.3和Mocha 1.0.0。你看过这个链接吗-