如何在 ruby​​ Test::Unit 框架中运行单个 shoulda 上下文测试

发布于 2024-08-09 10:50:32 字数 585 浏览 3 评论 0原文

我通常可以使用方法“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

雨落星ぅ辰 2024-08-16 10:50:32

这对我有用:

ruby functional/user_controller_test.rb -n "/Deleting a User/"

只需将上下文名称中的一些相当长的字符串放入正则表达式中即可。

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.

昔梦 2024-08-16 10:50:32

使用测试的全名并在末尾添加空格似乎也有效:

ruby -Itest 
     functional/user_controller_test.rb 
     -n "test: Deleting a user should remove user from user table. "

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. "
雨夜星沙 2024-08-16 10:50:32

结合这两种方法对我来说效果很好。同时使用 -I test 和正则表达式。

ruby -Itest functional/user_controller_teset.rb -n "/remove user from user table/"

Combining the two approaches has worked well for me; using both -I test and the regexp.

ruby -Itest functional/user_controller_teset.rb -n "/remove user from user table/"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文