开发者

Cucumber with Database_Cleaner for MySQL and MongoDB

I am building a Rails app that uses MySQL for some models and MongoDB for others (through the mongo_mapper gem).

We have started to build out cucumber (with capybara and webdriver) tests for the app and are coming across some trouble with IDs being referenced that don't exist. I believe I have tracked this down to old data in the MongoDB.

At this point, database_cleaner is doing its job with the MySQL records, but not the MongoDB ones.

There is a discussion at the cucumber-rails project about using MongoDB, but I be开发者_JS百科lieve it assumes that you are only using MongoDB, not both MongoDB and MySQL together.

Is there a way to have the database_cleaner clean both MySQL and MongoDB? Or is it only one or the other?

I found this article on how to drop all of the MongoDB content before running the tests, but I believe this will delete all data including the records I am using for local development...

Thanks.


Assuming you are doing something like this when you tell rails which Mongo DB to talk to:

MongoDatabase = "mongodb://localhost/yourdb_#{Rails.env}"

Then in your tests, do:

/spec/spec_helper.rb

MongoMapper.database.collections.select { |c| c.name != 'system.indexes' }.each(&:drop)  

(above is for MongoMapper, but idea is the same for Mongoid -- just drop to the database level and drop all collections).

This will only drop data in your test database, not your dev db. Used in conjunction with the DB cleaner, you're good to go.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜