Rspec运行所有测试,除了特定的文件夹。

问题描述 投票:23回答:3

我正在做的项目有一个相当大的测试套件。我目前正在编写测试,当我单独运行它时,它可以通过,但是当我运行整个测试套件时 $rspec 我得到了一些非常有趣的行为,导致测试失败。

现在,测试是这样嵌套的。

spec/folder1/folder2/folder3/test.rb

每个命令都能很好地运行测试,一切都通过了。

$rspec spec/folder1/folder2/folder3
$rspec spec/folder1/folder2
$rspec spec/folder1/

有大约10个其他的文件夹在同一个级别上 folder1 我想单独不与套件的其他部分一起运行,以确定哪个文件夹包含的测试破坏了我正在进行的测试。

这可能吗?

ruby rspec
3个回答
44
投票

使用一个 --exclude-pattern,他们相当方便。

https:/www.relishapp.comrspecrspec-corev3-3docsconfigurationexclude-pattern

他们的好处之一。

他们的好处之一是: --exclude-pattern 标志接受shell风格的glob联盟

所以你可以做这样的事情 rspec --exclude-pattern "spec/{foldername1,foldername2}/**/*_spec.rb"


2
投票

看一看 排除过滤器 中的Rspec项目,可能会有帮助。

您也可以通过使用 纳入过滤器.


0
投票

我知道这个问题是针对RSpec的,但是,我想知道如何用minitest来做这件事,而--exclude标志只过滤名称,而不是文件位置。

要在minitest中对文件位置进行过滤,你需要添加一个rake任务。

libtaskstest.rake

# lib/tasks/test.rake

Rake::Task["test:system"].clear

namespace :test do
  desc "Run all system tests except test/serial folder"
  task system: "test:prepare" do
    $: << "test"
    test_files = FileList["test/system/**/*_test.rb"].exclude(
      "test/system/serial/**/*_test.rb"
    )
    Rails::TestUnit::Runner.run(test_files)
  end

  desc "Run all serial test folder"
  task serial: "test:prepare" do
    $: << "test"
    test_files = FileList["test/system/serial/*_test.rb"]
    Rails::TestUnit::Runner.run(test_files)
  end
end
© www.soinside.com 2019 - 2024. All rights reserved.