0

我正在使用 Mongoid 3 运行 Rails 3。

我正在尝试删除活动记录并用 Mongoid 替换 RSpec 测试

这是我的配置/测试。这是我的spec_helper.rb

ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'

Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }

RSpec.configure do |config|

  #config.fixture_path = "#{::Rails.root}/spec/fixtures"
  #config.use_transactional_fixtures = true
  config.infer_base_class_for_anonymous_controllers = false
  config.order = "random"

  config.before(:suite) do
    DatabaseCleaner[:mongoid].strategy = :truncation
  end

  config.before(:each) do
    DatabaseCleaner[:mongoid].start
  end

  config.after(:each) do
    DatabaseCleaner[:mongoid].clean
  end
end

这是我的Gemfile(用于开发和测试)

group :development, :test do
  gem 'sqlite3', '1.3.5'
  gem 'rspec-rails',      ">= 2.0.0.beta"
  gem 'guard-rspec', '1.2.1'
  gem 'guard-spork', '1.2.0'
  gem 'childprocess', '0.3.6'
  gem 'spork', '0.9.2'
end

group :test do
  gem 'capybara', '1.1.2'
  gem "database_cleaner", "~> 1.1.1"
  gem 'factory_girl_rails', '4.1.0'
  gem "rb-inotify", "~> 0.9.0"
  gem "libnotify", "~> 0.8.0"
end

但是,当一个简单的数组拆分器测试(没有数据库操作)

require 'spec_helper'

describe ArrayHelper do
  describe "split array" do
    it "splits array up to three" do
      testArray = [1,2]
      result = splitTasks(testArray)
      result.should eq(Array(Array(1),Array(2)))
    end

我得到错误

`method_missing': undefined method `active_record' for #<Rails::Application::Configuration

想法?

结束结束

4

1 回答 1

1

我认为您应该 require "active_record/railtie" 从 confing/application.rb 文件中注释掉。

我希望这有帮助 :)

于 2013-12-25T13:48:13.603 回答