dboyd68
dboyd68

Reputation: 1104

Configure Rspec with Mongoid

I am running Rails 3 with Mongoid 3.

I am trying to remove active record and replace RSpec test with Mongoid

This is my config/test. this is my 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

This is my Gemfile (for dev and test)

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

However when a simple array splitter test(no db action)

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

I get the error

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

Ideas?

end end

Upvotes: 0

Views: 712

Answers (1)

Mawaheb
Mawaheb

Reputation: 832

I think you should comment out require "active_record/railtie" From within confing/application.rb file.

I hope this helps :)

Upvotes: 1

Related Questions