Can't clear Mongo DB while running test

654 views Asked by At

I am using rails, mongoid, spork, rspec.

While running tests via rspec I see increasing number of records in my database. Neither purge! nor database_cleaner didn't help.

My test is:

describe MyConvertor do
  context 'working with my model'
    before(:each) do
      FactoryGirl.create :my_model
    end
    # examples go here
  end
end

And my spec helper is:

Spork.each_run do
  RSpec.configure do |config|
    # ...
    config.before(:each) do
      Mongoid.purge!
    end
    # ...
  end
end

As I mentioned before I also tried database_cleaner as well but things didn't change:

Spork.prefork do
  RSpec.configure do |config|
    config.order = "random"
    config.use_transactional_fixtures = false
  end
end

Spork.each_run do
  RSpec.configure do |config|
    config.before(:suite) do
      DatabaseCleaner[:mongoid].strategy = :truncation
    end

    config.before(:each) do
      DatabaseCleaner.start
    end

    config.after(:each) do
      DatabaseCleaner.clean
    end
  end
end

So I have a couple of questions at once: why purge! does not do anything and why DatabaseCleaner does not work.

I have found a database cleaner issue, but there is no any helpful solution.

I am using

rails 3.2.11
mongoid 3.0.23
1

There are 1 answers

0
Nikhit On

I had this on Mac OSX el capitain:

on terminal:

brew doctor

it showed me this warning:

"Warning: /usr/bin occurs before /usr/local/bin This means that system-provided programs will be used instead of those provided by Homebrew."

Then i needed to change the order in /etc/paths, making "usr/local/bin" and "/usr/local/sbin" to be on top.

on terminal again:

sudo vi /etc/paths

/usr/local/bin
/usr/local/sbin
/usr/bin
/bin
/usr/sbin
/sbin

This solved the problem when I had it.