Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.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/6/opengl/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
Testing Rails Mocha gem-NoMethodError:未定义的方法'any#u instance';_Testing_Ruby On Rails 4_Mocha.js - Fatal编程技术网

Testing Rails Mocha gem-NoMethodError:未定义的方法'any#u instance';

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

我在一个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 < 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。

你看过这个链接吗-