gpt4 book ai didi

ruby-on-rails-3 - 只测试一个它或用 Rspec 描述

转载 作者:行者123 更新时间:2023-12-04 22:50:36 25 4
gpt4 key购买 nike

在 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"

关于ruby-on-rails-3 - 只测试一个它或用 Rspec 描述,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6518425/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com