在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"
您还可以选择要执行的测试用例所在的行。
rspec spec/models/user_spec.rb:8
通过传递测试用例范围内的任何行,将只执行此测试用例。您还可以使用它在测试中执行整个上下文。
至少在Rspec 2.11.1中,您可以使用以下所有选项:
**过滤/标签**
In addition to the following options for selecting specific files, groups, or examples, you can select a single example by appending the line number to the filename: rspec path/to/a_spec.rb:37 -P, --pattern PATTERN Load files matching pattern (default: "spec/**/*_spec.rb"). -e, --example STRING Run examples whose full nested names include STRING (may be used more than once) -l, --line_number LINE Specify line number of an example or group (may be used more than once). -t, --tag TAG[:VALUE] Run examples with the specified tag, or exclude examples by adding ~ before the tag. - e.g. ~slow - TAG is always converted to a symbol