Search code examples
ruby-on-railsrake

Testing rails application with rake


I would like to test specific folders in the rails application with rake. I have made a parallel.rake file in lib/tasks which contains:

require 'rake/testtask'
namespace :test do
    Rails::TestTask.new(fixtures: 'test:prepare') do |t|
        t.pattern = 'test/fixtures/*_test.rb'
    end
end

However, it keeps giving me an error:

rake aborted!
NameError: uninitialized constant Rails::TestTask

I have added require 'rake/testtask' to both the parallel.rake file and also the Rakefile.

All I want to do is run each folder in my tests folder separately. It contains these folders:
controllers
fixtures
integration
mailers
models

I know I can run controllers and integration folders by running the command rake test:integration and rake test:controllers.
But how do I test for the other folders?


Solution

  • Turns out it I was using Rails::TestTask instead of Rake::TestTask

    Just change the task file so it becomes:

    require 'rake/testtask'
      namespace :test do
        Rake::TestTask.new(fixtures: 'test:prepare') do |t|
          t.pattern = 'test/fixtures/*_test.rb'
      end
    end