Is it possible to run a single test in MiniTest?

2020-02-07 13:59发布

I can run all tests in a single file with:

rake test TEST=path/to/test_file.rb

However, if I want to run just one test in that file, how would I do it?

I'm looking for similar functionality to:

rspec path/to/test_file.rb -l 25

14条回答
爷的心禁止访问
2楼-- · 2020-02-07 14:41

I'm looking for similar functionality to rspec path/to/file.rb -l 25

Yup! Use Nick Quaranto's "m" gem. With it you can say:

m spec/my_spec.rb:25
查看更多
祖国的老花朵
3楼-- · 2020-02-07 14:42

If you are using MiniTest with Rails 5+ the best way to run all tests in a single file is:

bin/rails test path/to/test_file.rb

And for a single test (e.g. on line 25):

bin/rails test path/to/test_file.rb:25

See http://guides.rubyonrails.org/testing.html#the-rails-test-runner

查看更多
啃猪蹄的小仙女
4楼-- · 2020-02-07 14:42

I use ruby /path/to/test -n /distinguishable word/

Edit: -n is a shorthand for --name. distinguishable word can be any string you put in the test description, I usually use some random word that I know won't be present in other tests' descriptions.

查看更多
女痞
5楼-- · 2020-02-07 14:45

The command should be:

% rake test TEST=test/test_foobar.rb TESTOPTS="--name=test_foobar1 -v"
查看更多
祖国的老花朵
6楼-- · 2020-02-07 14:46

Following will work

def test_abc
end

test "hello world"
end

This can run by

bundle exec ruby -I test path/to/test -n test_abc

bundle exec ruby -I test path/to/test -n test_hello_word
查看更多
Emotional °昔
7楼-- · 2020-02-07 14:46

rails test path/to/test_file.rb:25 will do it

查看更多
登录 后发表回答