开发者

RSpec setup for an application that depends on an external database from another application

I've had to add features to an application that depends on a database from another application. I've been able to set up a connection to this external database and pull data from it. However, I'm not sure how to get my main application开发者_开发技巧 to create a test database for this external application.

It would be awesome if there some way to pull in the schema for this database and create it in the same manner that 'rake db:test:prepare' does. Is there any configuration capabilities for RSpec to do this, or will I have to roll my own task?


I am not aware of any simple way to do this. You could have a sql schema prepared and load it in your test database trough a custom rake task

But if it is for testing, it might be a good idea for you to look into Factories For example Factory girl

"factory_girl is a fixtures replacement with a straightforward definition syntax, support for multiple build strategies (saved instances, unsaved instances, attribute hashes, and stubbed objects), and support for multiple factories for the same class (user, admin_user, and so on), including factory inheritance."

And a screencast


Is this a Rails app? If so, the db:test:prepare task and the related tasks will still work, even if you are using RSpec.


I ended up just running rake db:test:prepare for the external application and update the database configs of the application I'm developing to include the test DB for the external application. I'd like to automate the rake db:test:prepare for the external app, however I don't see myself updating its schema that often.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜