You can get the functionality you are looking for using generators. Basically you write templates for the files that the user should have (models, migrations, tests) and save them with your gemfile. You then allow the user to copy those files in using commands.
This is a good link that goes into much more detail on generators, but here is a small example that I used in one of my gems:
gem_name/lib/generators/gem_name/install_generator.rb
module GemName
class InstallGenerator < Rails::Generators::Base
include Rails::Generators::Migration
# Allow user to specify a different model name
argument :user_class, type: :string, default: "User"
# Templates to copy
source_root File.expand_path('../../../templates', __FILE__)
# Copy initializer into user app
def copy_initializer
copy_file('create_initializer.rb', 'config/initializers/gem_name.rb')
end
# Copy user information (model & Migrations) into user app
def create_user_model
fname = "app/models/#{user_class.underscore}.rb"
unless File.exist?(File.join(destination_root, fname))
template("user_model.rb", fname)
else
say_status('skipped', "Model #{user_class.underscore} already exists")
end
end
# Copy migrations
def copy_migrations
if self.class.migration_exists?('db/migrate', "create_gem_name_#{user_class.underscore}")
say_status('skipped', "Migration create_gem_name_#{user_class.underscore} already exists")
else
migration_template('create_gem_name_users.rb.erb', "db/migrate/create_gem_name_#{user_class.pluralize.underscore}.rb")
end
end
private
# Use to assign migration time otherwise generator will error
def self.next_migration_number(dir)
Time.now.utc.strftime("%Y%m%d%H%M%S")
end
end
end
Finally, just some advice/personal opinion; your gem should either run under a variety of test suites and databases or else you should indicate that you only support that setup and assume they are available in the user's project. Though I think you could shoehorn in a second test suite, trying to force a second database wouldn't be possible, also you don't need to worry about the DB using migrations unless you want to use a data type that isn't available in all the supported DBs.
A better approach, in my opinion, would be to write separate generators for the specs you want and let the user run them optionally. This will copy the tests in and allow them to modify if they like.