我正在尝试在我的Rails 3项目中使用mocha但是仍然遇到以下异常:
NoMethodError: undefined method `mock' for #<MochaTest:0x00000101f434e8>
/Users/John/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.0.10/lib/action_dispatch/testing/assertions/routing.rb:175:in `method_missing'
test/functional/mocha_test.rb:7:in `block in <class:MochaTest>'
测试
我写过最简单的测试:
require 'test_helper'
class MochaTest < ActionController::TestCase
test "test mocha" do
order = mock('order')
end
end
我使用ruby -Itest test/functional/mocha_test.rb
我已经尝试了rake test
并且它提供了完全相同的异常。
test_helper.rb中
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
class ActiveSupport::TestCase
#....
require 'test/unit'
require 'mocha'
end
的Gemfile
source 'http://rubygems.org'
gem 'rails', '3.0.10'
gem 'sqlite3'
gem 'devise', '1.4.5'
gem 'activemerchant'
gem 'geo_location'
gem 'nokogiri'
gem "nifty-generators", :group => :development
gem 'mocha', '0.10.0'
我尝试过的事情
undefined method name
例外答案 0 :(得分:11)
我发布这个后立即找到了答案。
以下是答案:Mocha Mock Carries To Another Test
简而言之,我改变了
gem 'mocha', '0.10.0'
到
gem 'mocha', '0.10.0', :require => false
它就像一个魅力!