jimweirich / rake

A make-like build utility for Ruby.
http://rake.rubyforge.org/
1.1k stars 10 forks source link

Bug in 10.3.1 using Rails engine #270

Closed jsborjesson closed 10 years ago

jsborjesson commented 10 years ago

Hi! Just upgraded from 10.2.2 to 10.3.1, it seems to work fine in a normal rails app, but suddenly I got this error when running inside a rails engine:

$ rake -T
You must `gem install bundler` and `bundle install` to run rake tasks
rake aborted!
LoadError: cannot load such file -- rails/tasks/engine.rake
/Users/alcesleo/Projects/keymail/Rakefile:9:in `load'
/Users/alcesleo/Projects/keymail/Rakefile:9:in `<top (required)>'
(See full trace by running task with --trace)

It started working like before as soon as I downgraded the Rake version. I have no idea why but I'll be happy to provide more information if needed.

R.I.P Jim

drbrain commented 10 years ago

Since this is a LoadError with nothing pointing back to rake it seems to be a load path problem not a rake problem.

Here are the files that changed between rake 10.2.2 and 10.3.1: https://github.com/jimweirich/rake/compare/v10.2.2...v10.3.1#files_bucket, nothing points to a failure in load.

Why are you using load instead of require?

jsborjesson commented 10 years ago

This confuses me as well, but the only thing that changed to introduce this was the rake version, and it goes away when downgrading again like clockwork...

Truth is I'm not sure why I'm using load instead of require, the Rakefile is generated by rails plugin new whatever --mountable and looks like this:

begin
  require 'bundler/setup'
rescue LoadError
  puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end

require 'rdoc/task'

RDoc::Task.new(:rdoc) do |rdoc|
  rdoc.rdoc_dir = 'rdoc'
  rdoc.title    = 'Whatever'
  rdoc.options << '--line-numbers'
  rdoc.rdoc_files.include('README.rdoc')
  rdoc.rdoc_files.include('lib/**/*.rb')
end

APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
load 'rails/tasks/engine.rake'

Bundler::GemHelper.install_tasks

require 'rake/testtask'

Rake::TestTask.new(:test) do |t|
  t.libs << 'lib'
  t.libs << 'test'
  t.pattern = 'test/**/*_test.rb'
  t.verbose = false
end

task default: :test
drbrain commented 10 years ago

Can you puts $LOAD_PATH before the load 'rails/tasks/engine.rake'?

jsborjesson commented 10 years ago

It magically works the third time I installed the new version... No clue why, I tried it a couple of times yesterday and today everything is working with both of the mentioned versions.

I don't know what but it must have been something I did wrong the first two times, sorry for the inconvenience!

drbrain commented 10 years ago

No problem!

coteyr commented 8 years ago

I know it's closed but I came across this same problem. The cause was a dependency failing to load in the engine. In my case I required a gem that was not installed in the test/dummy application, and it produced this error message.

In other words the error was misleading, test/dummy/config/application.rb was failing to load, and it presented as this error message instead.

schneems commented 7 years ago

I had to add

  s.add_development_dependency "railties"

To a gemspec.