使用 `ruby` 命令运行

您可以使用 `ruby` 命令运行规范。您只需要需要 `rspec/autorun`。

一般来说,您最好使用 `rspec` 命令,这可以避免 `rspec/autorun` 的复杂性(例如,不需要 `at_exit` 钩子!),但某些工具仅适用于 `ruby` 命令。

从规范文件中需要 `rspec/autorun`

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

require 'rspec/autorun'

RSpec.describe 1 do
  it "is < 2" do
    expect(1).to be < 2
  end

  it "has an intentional failure" do
    expect(1).to be > 2
  end
end

我运行 `ruby example_spec.rb`

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

并且输出应包含“expect(1).to be > 2”。