This project is archived and is in readonly mode.

#3935 ✓invalid
scottsymm (at gmail)

rake aborted! no such file to load --

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

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

Comments and changes to this ticket

  • scottsymm (at gmail)

    scottsymm (at gmail) February 12th, 2010 @ 08:57 PM

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

  • scottsymm (at gmail)

    scottsymm (at gmail) February 12th, 2010 @ 09:11 PM

    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

  • José Valim

    José Valim February 16th, 2010 @ 10:37 PM

    • Assigned user set to “Carl Lerche”
  • Lenary

    Lenary April 17th, 2010 @ 11:44 PM

    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.

  • Ryan Bigg

    Ryan Bigg April 26th, 2010 @ 09:29 AM

    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.

  • José Valim

    José Valim April 26th, 2010 @ 09:33 AM

    • 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.

  • Ryan Bigg

    Ryan Bigg April 26th, 2010 @ 09:43 AM

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

  • José Valim

    José Valim April 26th, 2010 @ 09:44 AM

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

  • Ryan Bigg

    Ryan Bigg April 26th, 2010 @ 09:49 AM

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

  • José Valim

    José Valim April 26th, 2010 @ 09:53 AM

    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. :)

  • Ryan Bigg

    Ryan Bigg April 26th, 2010 @ 09:54 AM

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

  • José Valim
  • Lenary

    Lenary April 26th, 2010 @ 10:08 PM

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

  • Jeremy Kemper

    Jeremy Kemper April 26th, 2010 @ 10:24 PM

    • 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.

  • cocoOS

    cocoOS May 22nd, 2010 @ 05:31 AM

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

  • Jeremy Kemper

    Jeremy Kemper October 15th, 2010 @ 11:01 PM

    • Milestone set to 3.0.2
    • Importance changed from “” to “Low”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages