【问题标题】:How to run a single shoulda context test in ruby Test::Unit framework如何在 ruby​​ Test::Unit 框架中运行单个 shoulda 上下文测试
【发布时间】:2009-10-29 06:59:54
【问题描述】:

我通常可以使用以下命令行语法来测试常规 Test::Unit 方法,用于方法“delete_user_test”:

ruby functional/user_controller_test.rb -n delete_user_test

现在,当我使用带有 Test::Unit 的 shoulda 插件时,我尝试使用以下相同的技术:

... 
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 运行一个,而不必等待所有测试运行。

【问题讨论】:

    标签: ruby-on-rails ruby unit-testing shoulda


    【解决方案1】:

    这对我有用:

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

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

    【讨论】:

    • 有趣的是,在使用 shoulda 之前使用“/Deleting_a_User/”会起作用,但现在您可以并且实际上必须使用“/Deleting a User/”
    【解决方案2】:

    在末尾使用空格的测试全名似乎也可以:

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

    【讨论】:

      【解决方案3】:

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-01-17
        • 2010-12-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-05-22
        相关资源
        最近更新 更多