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

rake test TEST=path/to/test_file.rb

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

我正在寻找类似的功能:

rspec path/to/test_file.rb -l 25

当前回答

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

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

我也用过

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

为了更好的显示。

其他回答

以下将会起作用

def test_abc
end

test "hello world"
end

这可以通过

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

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

你有没有试过:

ruby path/to/test_file.rb --name test_method_name

安装gem minest -focus并使用关键字focus on test/spec,如下所示,只运行特定的测试。

focus
def test
end


focus
it "test" do
end

这将不需要传递任何命令行参数。

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

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

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

我也用过

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

为了更好的显示。