ruby on rails - Requiring a gem inside a gem's rake task -
i'm using jeweler create gem rails 3. gem contains rake task , 1 of things wiping db, i'm using 'database_cleaner'.
i'm specifying gem dependency inside gem's gemfile
gem 'database_cleaner'
and in rakefile
jeweler::tasks.new |gem| ... gem.add_dependency 'database_cleaner' end
then inside lib i've created files my_gem.rb , tasks.rake. follows, my_gem.rb:
module mygem class railtie < rails::railtie rake_tasks load 'tasks.rake' end end end
and tasks.rake:
task :my_task databasecleaner.strategy = :truncation databasecleaner.clean end
i installed gem (sudo rake install), created empty rails project , added gem dependency in rails' gemspec (gem 'my_gem'
). when try run rake my_task
error uninitialized constant databasecleaner
.
i've tried adding require 'database_cleaner'
inside task, raises error no such file load -- database_cleaner
, gem 'database_cleaner'
raises error database_cleaner not part of bundle. add gemfile.
.
is there way solve without adding gem 'database_cleaner'
rails project's gemspec?
thanks
update (adding link source code): https://github.com/jordinl/dummy_tasks
here did make work:
https://github.com/johnmcaliley/dummy_tasks/commits/master
tasks.rake
require 'database_cleaner' require 'dummy_tasks' namespace :db task :dummy => :environment databasecleaner.strategy = :truncation databasecleaner.clean rake::task['db:seed'].invoke end end
there may more elegant way this, should @ least prevent having add database_cleaner gem app gemfile
Comments
Post a Comment