如何指定RSpec"语法"命令行上的参数?

时间:2016-09-02 21:41:55

标签: ruby command-line rspec syntax

我们有一个shell脚本启动我们的RSpec测试。它看起来像这样:

args+=(
  "--format" "html"
  "--out" "$to_dir/index.html"
)

"$rspec_dir/rspec" "${args[@]}" "$tests_to_run"
exit $?

尝试升级RSpec时,我收到了:should语法被弃用的错误,我们需要明确启用它,如下所示:How to avoid deprecation warning for stub_chain in RSpec 3.0?

但是,由于我们不使用Rake,因此在通过命令行启动rspec时需要找到一种方法。但是当我尝试调整命令行选项时如此:

./rspec --format "html" --out "index.html" --syntax ":should"

它说--syntax不是有效选项。如何在通过命令行直接调用rspec时启用此不推荐使用的语法?

(我们无法使用Rake,因为我们的内部构建工具不支持它。这就是我需要通过命令行了解如何执行此操作的原因。)

1 个答案:

答案 0 :(得分:2)

您无法在命令行上配置RSpec期望和模拟语法。编辑项目的spec/spec_helper.rb以包含以下内容:

RSpec.configure do |config|
  config.expect_with :rspec do |expectations|
    expectations.syntax = [:should, :expect]
  end
  config.mock_with :rspec do |mocks|
    mocks.syntax = [:should, :expect]
  end
end

升级后,您可能希望更改所有示例以使用新语法(可能使用transpec),然后禁用:should语法。

更多信息https://relishapp.com/rspec/rspec-expectations/docs/syntax-configurationhttps://relishapp.com/rspec/rspec-mocks/docs/old-syntax/stub