Am building a gem that adds a user interface to another gem. I’m struggling with the best way to test this with hitting the database to make sure that roles are being set after specific calls.
Any recommendations on where to start researching this? I’ve already checked the normal places like edge rails.
As a general overview, you’re going to want to write integration specs for your gem. The integration specs will actually include a rails app in it which includes your gem and the other gem in the Gemfile, and will test them together.
I hope that points you in the right direction, let me know if I can provide any information or how it goes.
Yes, I recommend using FactoryGirl for test data, even with engines.
Even if you use FactoryGirl, you do still need the dummy/test Rails app to have a database, otherwise the app won’t run. But you don’t need to include an sqlite database, in fact we generally recommend using Postgres for everything. Either way, you can rake db:create either manually or as part of your automated test run, from within the test application and the database will be created if it doesn’t already exist.
From there, you can use your normal testing strategies within the app. FactoryGirl, relying as much as possible on build_stubbed, and also Rspec test doubles.
I’m looking into integration testing an Engine subscription gem. Are you saying that FactoryGirl does not need a Rails model but simply any fixture can be created and used? Then as you suggest use test doubles and stubbing?
Also where would the rake db:create be located for testing?
While FactoryGirl doesn’t need a Rails model, and can be used against normal Ruby classes, that is not what I was referring to here. What I am saying here is that FactoryGirl can be used within the testing of the Rails Engine in the same way that it can be used to test a normal Rails app.
Also where would the rake db:create be located for testing?
You can either run it manually or automate it as part of your test run.