如何在 ruby Test::Unit 框架中运行单个 shoulda 上下文测试
我通常可以使用方法“delete_user_test”的以下命令行语法来测试常规 Test::Unit 方法:
ruby functional/user_controller_test.rb -n delete_user_test
现在,当我将 shoulda 插件与 Test::Unit 一起使用时,我尝试使用相同的技术,如下所示:
...
context "Deleting a User" do
should "remove user from user table" do
...
end
end
然后我尝试按如下方式运行单个测试:
ruby functional/user_controller_test.rb -n "test: Deleting a User should remove user from user table"
这不起作用。有谁知道如何使用 shoulda 和 Test::Unit 运行单个上下文测试。我在一个测试文件中有几个不同的测试,我只想使用 TDD 运行一个测试,而不必等待所有测试运行。
I can typically test a regular Test::Unit method using the following commandline syntax for a method "delete_user_test":
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:
...
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. 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这对我有用:
只需将上下文名称中的一些相当长的字符串放入正则表达式中即可。
This works for me:
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:
结合这两种方法对我来说效果很好。同时使用
-I test
和正则表达式。Combining the two approaches has worked well for me; using both
-I test
and the regexp.