NoMethodError:Mocha和Rails 3的未定义方法“模拟" [英] NoMethodError: undefined method `mock' with Mocha and Rails 3

查看:65
本文介绍了NoMethodError:Mocha和Rails 3的未定义方法“模拟"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的Rails 3项目中使用摩卡,但是不断出现以下异常:

I'm trying to use mocha in my Rails 3 project but keep getting the following exception:

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>'

测试

我已经编写了最简单的测试:

I've written the simplest test possible:

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,它给出了完全相同的异常.

I've tried rake test and it gives exactly the same exception.

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'

我尝试过的事情

  • 在阅读0.9.5-7之后安装mocha 0.9.5遇到了问题.我得到一个undefined method name异常
  • 更改我需要摩卡的位置-在test_helper.rb的底部,测试的顶部等.
  • 在Rails控制台测试中尝试调用模拟()-我遇到了相同的异常
  • Installing mocha 0.9.5 after reading 0.9.5-7 had issues with this. I get an undefined method name exception instead
  • Changing where I require mocha - at the bottom of test_helper.rb, top of test etc.
  • Tried calling mock() in rails console test - I get the same exception

我要把它扯掉.任何想法将不胜感激.

I'm tearing my hair out with this. Any ideas would be gratefully received.

推荐答案

发布此消息后,我立即找到了答案.

I found the answer immediately after I'd posted this.

答案是:摩卡咖啡模拟进行另一项测试

简而言之,我改变了

gem 'mocha', '0.10.0'

gem 'mocha', '0.10.0', :require => false

它像一种魅力一样起作用!

and it worked like a charm!

这篇关于NoMethodError:Mocha和Rails 3的未定义方法“模拟"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆