--dry-run 选项

使用 --dry-run 选项让 RSpec 打印套件的格式化程序输出,而无需运行任何示例或钩子。

使用 --dry-run

给定一个名为“spec/dryrunspec.rb”的文件,其中包含

RSpec.configure do |c|
  c.before(:suite) { puts "before suite" }
  c.after(:suite)  { puts "after suite"  }
end

RSpec.describe "dry run" do
  before(:context) { fail }
  before(:example) { fail }

  it "fails in example" do
    fail
  end

  after(:example) { fail }
  after(:context) { fail }
end

我运行 rspec --dry-run

那么输出应该包含“1 个示例,0 个失败”

并且输出不应包含“套件之前”

并且输出不应包含“套件之后”。