Is it possible to run a single test in MiniTest?
I'm looking for similar functionality to rspec path/to/file.rb -l 25
With Nick Quaranto's "m" gem, you can say:
m spec/my_spec.rb:25
How do I run a single test file in minitest?
bin/rails test test/controllers/issues_controller_test.rb
How to run MiniTest::Unit tests in ordered sequence?
You can use i_suck_and_my_tests_are_order_dependent!()
class method.
class MyTest < MiniTest::Unit::TestCase
i_suck_and_my_tests_are_order_dependent! # <----
def test_1
p 1
end
def test_2
p 2
end
end
But as the name suggest, it's not a good idea to make the tests to be dependant on orders.
How to run a single test from a Rails test suite?
NOTE: This doesn't run the test via rake
. So any code you have in Rakefile
will NOT get executed.
To run a single test, use the following command from your rails project's main directory:
ruby -I test test/unit/my_model_test.rb -n test_name
This runs a single test named "name", defined in the MyModelTest class in the specified file. The test_name is formed by taking the test name, prepending it with the word "test", then separating the words with underscores. For example:
class MyModelTest < ActiveSupport::TestCase
test 'valid with good attributes' do
# do whatever you do
end
test 'invalid with bad attributes' do
# do whatever you do
end
end
You can run both tests via:
ruby -I test test/unit/my_model_test.rb
and just the second test via
ruby -I test test/unit/my_model_test.rb -n test_invalid_with_bad_attributes
How to run all tests with minitest?
Here's a link to Rake::TestTask.
There is an example in the page to get you started.
I'll post another one that I'm using right now for a gem:
require 'rake/testtask'
Rake::TestTask.new do |t|
t.pattern = "spec/*_spec.rb"
end
As you can see, I assume that my files are all in /lib
and that my specs are in /spec
and are named whatever_spec.rb
Hope it helps.
Globbing doesn't work with Minitest - Only one file is run
This is not minitest specific, but Ruby. You are effectively running a ruby program which knows nothing about the program being run.
Ruby does not support running multiple files at once afaik, so if you want to get a similar result you could try something like:
for file in spec/**/*_spec.rb; do ruby $file; done
UPDATE: for what you want you should probably create a Rake task as described here
Related Topics
Differencebetween Send_Data and Send_File in Ruby on Rails
How to Have Multiple Versions of Ruby and Rails, and Their Combinations on Windows
Differencebetween Class and Klass in Ruby
Ruby on Rails Plural (Controller) and Singular (Model) Convention - Explanation
Ruby on Rails: How to Run Things in the Background
Removing All Empty Elements from a Hash/Yaml
Where to Define Custom Error Types in Ruby And/Or Rails
How to Run a Single Test in Minitest
Welcome/Home Page in Ruby on Rails - Best Practice
Ubuntu Rails Install Fails on Zlib
How to Install Rvm System Requirements Without Giving Sudo Access for Rvm User
How to Test a File Upload in Rails
File Upload with Activeadmin Rails Using Paperclip
How to Sort an Array of Hashes by a Value in the Hash
Can Someone Explain the Class.Superclass.Class.Superclass Paradox