Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

rake aborted! no such file to load --

#3935

Should i be able to load a gem into a rake task?

I am new to ruby and rails, but this seems like it should work.

lib/tasks/foo.rake

namespace :foo do
task :bar => :environment do

require 'faker'
puts "foobar"

end end

$ rake foo:bar --trace (in /Users/home/dev/rails3) Invoke foo:bar (first_time) Invoke environment (first_time) Execute environment Execute foo:bar rake aborted!
no such file to load -- faker

$gem list LOCAL GEMS faker (0.3.1)

$ rake about (in /Users/home/dev/rails3) About your application's environment
Ruby version 1.9.1 (i386-darwin9.8.0)
RubyGems version 1.3.5
Rack version 1.1
Rails version 3.0.0.beta
Active Record version 3.0.0.beta
Action Pack version 3.0.0.beta
Active Resource version 3.0.0.betaAction Mailer version 3.0.0.betaActive Support version 3.0.0.beta
Middleware ActionDispatch::Static, Rack::Lock, Rack::Runtime, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::Callbacks, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, Rack::MethodOverride, ActionDispatch::Head
Application root /Users/home/dev/rails3
Environment development

/Users/home/.rvm/gems/ruby-1.9.1-p378/bin/rails /Users/home/.rvm/rubies/ruby-1.9.1-p378/bin/rake /Users/home/.rvm/rubies/ruby-1.9.1-p378/bin/gem /Users/home/.rvm/rubies/ruby-1.9.1-p378/bin/ruby

Reported by scottsymm (at gmail) · February 11th, 2010 @ 10:26 PM

State: invalid
Milestone: 3.0.2
Assigned to: José Valim José Valim
Importance: Low

Activity

  1. scottsymm (at gmail)
    scottsymm (at gmail)

    i was able to reproduce with ruby 1.8.7 (2010-01-10 patchlevel 249) [i686-darwin9.8.0]

    February 12th, 2010 @ 08:57 PM

  2. scottsymm (at gmail)
    scottsymm (at gmail)

    unpacking the gem in vendor/plugins/ seems to work for me. although, rake call does generate a warning:

    DEPRECATION WARNING: Having rake tasks in PLUGIN_PATH/tasks or PLUGIN_PATH/rails/tasks is deprecated. Use to PLUGIN_PATH/lib/tasks instead.

    cd vendor/plugins
    gem unpack faker

    February 12th, 2010 @ 09:11 PM

  3. José Valim
    José Valim
    • Assigned user set to Carl Lerche

    February 16th, 2010 @ 10:37 PM

  4. Lenary
    Lenary

    Indeed I came across this problem as well, and it's completely reproducible.

    This said, there is an easy workaround, which uses Bundler as is easy.

    In your bundle file, declare the following:

        group :rake do
          gem 'faker'
        end
    

    and then add the following to your Rakefile, or even to the top of the individual rake task:

        Bundler.require(:rake)
    

    then all your problems are solved.

    April 17th, 2010 @ 11:44 PM

  5. Ryan Bigg
    Ryan Bigg

    If this is inheriting from the :environment task then shouldn't that be the one that's loading these gems? I don't think the rake group workaround is the best idea.

    April 26th, 2010 @ 09:29 AM

  6. José Valim
    José Valim
    • Milestone cleared.
    • State changed from new to open
    • Assigned user changed from Carl Lerche to José Valim

    +1 for Lenary suggestion. If you want to use faker in development and test as well, it's ok to put it under the environment group.

    Maybe we could even "Bundler.require(:rake)" by default in the Rakefile. It should be discussed.

    April 26th, 2010 @ 09:33 AM

  7. Ryan Bigg
    Ryan Bigg

    Uh, shouldn't that be inside the :environment task where this inherits from? That would make more sense, no?

    April 26th, 2010 @ 09:43 AM

  8. José Valim
    José Valim

    Sorry Ryan, I guess I misunderstood you. Can you please give an example?

    April 26th, 2010 @ 09:44 AM

  9. Ryan Bigg
    Ryan Bigg

    I am suggesting that this Bundler.require(:rake) be put into task :environment definition rather than in the Rakefile of the application.

    April 26th, 2010 @ 09:49 AM

  10. José Valim
    José Valim

    It's better to avoid adding bundler inside the framework. We should do our best to have bundler just in the generated application in order to be packaging system agnostic. :)

    April 26th, 2010 @ 09:53 AM

  11. Ryan Bigg
    Ryan Bigg

    Ah right, of course, then yes Lenary's suggestion is fine. Sorry for the confusion.

    April 26th, 2010 @ 09:54 AM

  12. José Valim
  13. Lenary
    Lenary

    I'm just about to write a generator patch for this. :D

    April 26th, 2010 @ 10:08 PM

  14. Jeremy Kemper
    Jeremy Kemper
    • State changed from open to invalid

    -1 on an additional Bundler.require

    Looks like faker is just missing from the OP's Gemfile. Add it, bundle, and you're good to go.

    April 26th, 2010 @ 10:24 PM

  15. cocoOS
    cocoOS

    the problem is machinist require faker..It solve delete(or coment) require 'faker' inside machinist.rb..I had the same problem :).....

    May 22nd, 2010 @ 05:31 AM

  16. Jeremy Kemper
    Jeremy Kemper
    • Milestone set to 3.0.2
    • Importance changed from to Low

    October 15th, 2010 @ 11:01 PM