Search code examples
ruby-on-railsrubyruby-on-rails-4rake

Don't know how to build task 'db:seed_fu'


I have just added the seed-fu gem to my app for seeding my test-database:

group :test do
  gem 'seed-fu'
end

I made a custom rake task (in /lib/tasks/db.rake) for seeding only my test-database:

namespace :db do

  desc "seed_fu only in test-database"
  task seed_fu_test: :environment do
    Rails.env = 'test'
    puts "Seeding will be made in test-base ONLY!"
    Rake::Task["db:seed_fu"].execute
  end

end

If I do rake -T | grep seed then my new custom-made task is shown amongst other seed-tasks:

rake db:seed                            # Load the seed data from db/seeds.rb
rake db:seed_fu                         # Loads seed data for the current environment
rake db:seed_fu_test                    # seed_fu only in test-database

Now when I do rake db:seed_fu_test I get

rake aborted!

Don't know how to build task 'db:seed_fu'

But when I do

rake db:seed_fu RAILS_ENV='test'

then seed_fu seeds my test-database well.


Solution

  • Figured it out- the problem was in my Gemfile. Because I added the seed-fu gem into test-group then in development-environment, which was my default for running also the rake db:seed_fu_test task, the seed_fu gem was not seen.

    Therefore when moving gem 'seed-fu' line into my :development-group in Gemfile, the problem was solved.