I have many tests like creating user, updating, etc. In some of the controllers I have access to a Mongo Database. The problem is that it also accesses it when doing the tests, adding data to the database.
Is there a way to block access to开发者_高级运维 the test suite to that code? It becomes annoying every time I run the tests I get more 100 rows.
Thanks
Are you defining access to the mongo database in your database.yml? If so, set up a connection for the test environment:
development: &default_settings
database: APPNAME_development
host: 127.0.0.1
port: 27017
test:
<<: *default_settings
database: APPNAME_test
If you are accessing the mongo database through some sort of web service API, then you can use a combination of fakeweb and VCR to record the requests and responses to it. Subsequent requests from your tests to the service will serve up the cached response rather than hitting it directly.
https://github.com/myronmarston/vcr
精彩评论