我可以在一个文件中运行所有测试:
rake test TEST=path/to/test_file.rb
但是,如果我只想在该文件中运行一个测试,我该怎么做呢?
我正在寻找类似的功能:
rspec path/to/test_file.rb -l 25
我可以在一个文件中运行所有测试:
rake test TEST=path/to/test_file.rb
但是,如果我只想在该文件中运行一个测试,我该怎么做呢?
我正在寻找类似的功能:
rspec path/to/test_file.rb -l 25
当前回答
我使用ruby /path/to/test -n /distinguishable word/
编辑: -n是——name的缩写。可区分的单词可以是你放在测试描述中的任何字符串,我通常使用一些随机的单词,我知道这些单词不会出现在其他测试的描述中。
其他回答
你可以通过——name来运行一个测试,通过它的名字或者它名字中的一个数字:
-n, --name PATTERN Filter run on /regexp/ or string.
例如:
$ ruby spec/stories/foo_spec.rb --name 3
FAIL (0:00:00.022) test_0003_has foo
Expected: "foo"
Actual: nil
这个标志被记录在Minitest的README中。
你有没有试过:
ruby path/to/test_file.rb --name test_method_name
不需要宝石: ruby - test test/lib/testRb——name /some_test/
来源:http://blog.arvidandersson.se/2012/03/28/minimalicous-testing-in-ruby-1-9
安装gem minest -focus并使用关键字focus on test/spec,如下所示,只运行特定的测试。
focus
def test
end
focus
it "test" do
end
这将不需要传递任何命令行参数。
我正在寻找类似的功能: / / test_file rspec路径。Rb -l 25
有一种宝石正是这样做的:最小行。
gem install minitest-line
ruby test/my_file -l 5
从https://github.com/judofyr/minitest-line minitest-line