加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails-3 – 仅测试一个或用Rspec描述

发布时间:2020-12-17 03:52:49 所属栏目:百科 来源:网络整理
导读:在TestUnit上,您可以使用-n选项在文件中启动一个测试 例如 require 'test_helper'class UserTest ActiveSupport::TestCase test "the truth" do assert true end test "the truth 2" do assert true endend 你只能执行测试真相 ruby -Itest test/unit/user_t
在TestUnit上,您可以使用-n选项在文件中启动一个测试

例如

require 'test_helper'

class UserTest < ActiveSupport::TestCase

  test "the truth" do
    assert true
  end

  test "the truth 2" do
    assert true
  end

end

你只能执行测试真相

ruby -Itest test/unit/user_test.rb -n test_the_truth

输出

1 tests,1 assertions,0 failures,0 errors,0 skip

怎么能用rspec?

该命令似乎不起作用

rspec spec/models/user_spec.rb -e "User the truth"

解决方法

您没有包含规范的来源,因此很难说问题出在哪里,但通常您可以使用-e选项运行单个示例.鉴于此规范:

# spec/models/user_spec.rb
require 'spec_helper'
describe User do

  it "is true" do
    true.should be_true
  end

  describe "validation" do
    it "is also true" do
      true.should be_true
    end
  end

end

这个命令行:

rspec spec/models/user_spec.rb -e "User is true"

会产生这样的输出:

Run filtered including {:full_description=>/(?-mix:User is true)/}
.

Finished in 0.2088 seconds
1 example,0 failures

如果你想调用另一个嵌套在验证组内的例子,你可以使用它:

rspec spec/models/user_spec.rb -e "User validation is also true"

或者运行验证组中的所有示例:

rspec spec/models/user_spec.rb -e "User validation"

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读