I put this code inside my Rakefile in order to be able to run tests from an additional folder "test/classes" (not just from test/models, test/controllers etc):
# Adding test/classes directory to rake test.
namespace :test do # line 9
desc "Test tests/classes/* code"
Rails::TestTask.new(parsers: 'test:prepare') do |t| # line 11
t.pattern = 'test/classes/**/*_test.rb'
end
end
Rake::Task['test:run'].enhance ["test:classes"]
This code works perfectly when I run rails test
.
But when I run rails db:migrate
, I get this error:
NameError: uninitialized constant Rails::TestTask
/Users/Developer/project/Rakefile:11:in `block in <top (required)>'
/Users/Developer/project/Rakefile:9:in `<top (required)>'
What do I do to get rid of the error, but still be able to load test files from
insert
require 'rake/testtask'
into Rakefile
I saw this during a Rails 5.2 upgrade (from Rails 4.2). The fix for me was to rename Rails::TestTask
to Rake::TestTask
everywhere.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With