Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Reset database #31

Closed
jakecraige opened this issue Feb 10, 2015 · 4 comments
Closed

Feature request: Reset database #31

jakecraige opened this issue Feb 10, 2015 · 4 comments

Comments

@jakecraige
Copy link

It would be awesome if monky kept track of what it created and we could call a method to reset the database.

@behrendtio
Copy link
Owner

Hm I'm not sure if that's a good idea or not, yet. Keeping track of all the created models is certainly easy, but you could build models with monky and save them later on in your tests without monky knowing about it.

Furthermore it would increase monky's footprint quite a lot for a very "small" feature.

In general from my experience you'd want to clean the whole (test) database anyways for each run of a test don't you? What I could potentially see is either a monky feature like monky.clearDatabase() or a separate monky plugin.

On the other hand, clearing the database should be as simple as doing connection.db.dropDatabase() on the mongoose connection. So it's not really saving you any code doing it via monky instead of directly.

What do you think, did you have something else in mind?

@janckerchen
Copy link

It make sense to only clean specific collections, not entire db, for example, I will clean 'User' collection after register test suit.

@jakecraige
Copy link
Author

My inspiration for this idea was this project https://github.com/DatabaseCleaner/database_cleaner It's almost unanimously used in rails testing stacks. It's pretty frustrating to have to clean out the db before every test that uses it. Once you get a larger test suite, lots of it would begin with cleaning out the test suite rather than have something you could hook into automatically to do it.

@behrendtio
Copy link
Owner

Yeah I know database_cleaner and use it myself quite a lot. And it's a very good example why it should not be a part of monky, but a separate module. Cleaning the user collection is fairly simple with mongoose, so I'm closing this as a "won't change".

I'd suggest to write a separate module just like database_cleaner - or a module called monky-clean or so, which monkey patches monky with something like monky.clear() and monky.clear('user'), which hooks into the respective test runner like mocha. Perhaps even with plugins for each test runner. So it's not a trivial thing and would totally be too much functionality for monky.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants