Prevent rspec from trying to connect to mongoid

I am running rails with mongoid as my db with connections in my mongoid.yml file.

The problem is that every time I run rspec it tries to connect to the back end of mongodb.

I want to stop this behavior and use mocks for my tests.

How can I achieve this?

+3


source to share


1 answer


For unit tests in rspec, if you make Mongoid persistence calls on model objects, you will instead need to replace those persistence calls with mock / stubbing calls. For example, factory -girl provides mock implementations of your model objects, which you can then use in your unit tests by invoking the volatility methods ala ...

person = FactoryGirl.build(:person)
person.should be_a_kind_of Person

      



Avoid calling methods that persist in the test database, such as "FactorGirl.create"

0


source







All Articles