我可以在一个文件中运行所有测试:

rake test TEST=path/to/test_file.rb

但是,如果我只想在该文件中运行一个测试,我该怎么做呢?

我正在寻找类似的功能:

rspec path/to/test_file.rb -l 25

当前回答

如果你在minitest中使用Turn gem,请确保使用Turn.config.pattern选项,因为Turn minitest运行器不尊重arg中的——name选项。

其他回答

如果你正在使用MiniTest和Rails 5+,最好的方法是在一个文件中运行所有测试:

bin/rails test path/to/test_file.rb

对于单个测试(例如在第25行):

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

看到http://guides.rubyonrails.org/testing.html the-rails-test-runner

我正在寻找类似于rspec path/to/file的功能。Rb -l 25

用尼克·夸兰托的"m"宝石,你可以说:

m spec/my_spec.rb:25

我正在寻找类似的功能: / / test_file rspec路径。Rb -l 25

有一种宝石正是这样做的:最小行。

gem install minitest-line
ruby test/my_file -l 5

从https://github.com/judofyr/minitest-line minitest-line

你可以用它来运行一个文件:

rake test TEST=test/path/to/file.rb

我也用过

ruby -I"lib:test" test/path/to/file.rb

为了更好的显示。

我使用ruby /path/to/test -n /distinguishable word/

编辑: -n是——name的缩写。可区分的单词可以是你放在测试描述中的任何字符串,我通常使用一些随机的单词,我知道这些单词不会出现在其他测试的描述中。