[英]How to run a single shoulda context test in ruby Test::Unit framework
I can typically test a regular Test::Unit method using the following commandline syntax for a method "delete_user_test": 我通常可以使用以下命令行语法为方法“delete_user_test”测试常规的Test :: Unit方法:
ruby functional/user_controller_test.rb -n delete_user_test
Now when I'm using the shoulda plugin with Test::Unit I try to use the same technique as follows: 现在,当我使用带有Test :: Unit的shoulda插件时,我尝试使用如下相同的技术:
...
context "Deleting a User" do
should "remove user from user table" do
...
end
end
Then I try to run the single test as follows: 然后我尝试按如下方式运行单个测试:
ruby functional/user_controller_test.rb -n "test: Deleting a User should remove user from user table"
This doesn't work. 这不起作用。 Does anyone know how I can run a single context tests using shoulda and Test::Unit. 有谁知道如何使用shoulda和Test :: Unit运行单个上下文测试。 I have a couple of different test in one test file and I want to only run the one using TDD without having to wait for all tests to run. 我在一个测试文件中有几个不同的测试,我想只使用TDD运行一个,而不必等待所有测试运行。
This works for me: 这对我有用:
ruby functional/user_controller_test.rb -n "/Deleting a User/"
Just put some reasonably long string from your context name into the regular expression. 只需将您的上下文名称中的一些相当长的字符串放入正则表达式中。
Using the full name of the test with a space at the end seems to work too: 使用最后一个空格的测试的全名似乎也有效:
ruby -Itest
functional/user_controller_test.rb
-n "test: Deleting a user should remove user from user table. "
Combining the two approaches has worked well for me; 结合这两种方法对我来说效果很好; using both -I test
and the regexp. 同时使用-I test
和regexp。
ruby -Itest functional/user_controller_teset.rb -n "/remove user from user table/"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.