Note that there are some explanatory texts on larger screens.

plurals
  1. PORequiring a gem inside a gem's rake task
    primarykey
    data
    text
    <p>I'm using jeweler to create a gem for Rails 3. The gem contains a rake task and one of the things it does is wiping the DB, so I'm using 'database_cleaner'.</p> <p>I'm specifying the gem dependency inside the gem's Gemfile</p> <pre><code>gem 'database_cleaner' </code></pre> <p>And in the Rakefile</p> <pre><code>Jeweler::Tasks.new do |gem| ... gem.add_dependency 'database_cleaner' end </code></pre> <p>Then inside lib I've created the files my_gem.rb and tasks.rake. As follows, my_gem.rb:</p> <pre><code>module MyGem class Railtie &lt; Rails::Railtie rake_tasks do load 'tasks.rake' end end end </code></pre> <p>And tasks.rake:</p> <pre><code>task :my_task do DatabaseCleaner.strategy = :truncation DatabaseCleaner.clean end </code></pre> <p>I installed the gem (sudo rake install), created an empty rails project and added the gem dependency in the rails' Gemspec (<code>gem 'my_gem'</code>). But when I try to run <code>rake my_task</code> I get the error <code>uninitialized constant DatabaseCleaner</code>.</p> <p>I've also tried adding <code>require 'database_cleaner'</code> from inside the task, which raises the error <code>no such file to load -- database_cleaner</code> and <code>gem 'database_cleaner'</code> that raises the error <code>database_cleaner is not part of the bundle. Add it to Gemfile.</code>.</p> <p>Is there a way to solve this without adding <code>gem 'database_cleaner'</code> to the rails project's Gemspec?</p> <p>Thanks</p> <p>UPDATE (adding the link to the source code): <a href="https://github.com/jordinl/dummy_tasks" rel="noreferrer">https://github.com/jordinl/dummy_tasks</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload