1
votes

Here's a layup for someone...

Back in Rails <= 4 days we'd run our test suite by simply typing $ rake at the command line, thanks to defaults in Rakefile:

task default: [:rubocop, :spec, :teaspoon]

but in Rails 5 it's not so apparent how to run default rake tasks now that rake has been replaced by rails. rails alone gives a list of possible commands rails responds to but doesn't run the specs. rails test seems logical but it tries to run minitest which we don't use. rails spec will run Rspec but not teaspoon or rubocop.

Where did this go? And why is something so apparently simple so hard for me to look up myself?

2

2 Answers

2
votes

rails default executes those tasks for me on Rails 5.2.1, though I couldn't find it documented anywhere.

0
votes

Just create a new rake task that runs the other ones:

task :my_test do
  Rake::Task[:foo].invoke
  Rake::Task[:bar].invoke
end
# or the short version:
# task my_test: [:foo, :bar]

task :foo do
  puts "FOO"
end

task :bar do
  puts "BAR"
end

Run rails my_test and you will see FOO and BAR printed in your console.

If you don't know where to place the file to write the code above, check your /Rakefile:

# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require_relative 'config/application'

Rails.application.load_tasks

It says to write them inside lib/tasks and end them with .rake, you don't need to require them. In your specific question, change my code from :foo and :bar to your specific tasks :rubocop :spec :teaspoon.

However, it looks like you are doing some BDD or TDD cycle. Check out rails Guard, it might help you better. I use it in my project and it works perfectly.