【问题标题】:How to specify the RSpec "syntax" parameter on the command line?如何在命令行中指定 RSpec “语法”参数?
【发布时间】:2016-09-02 21:41:55
【问题描述】:

我们有一个 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,因为我们的内部构建工具不支持它。这就是为什么我需要通过命令行找出如何做到这一点。)

【问题讨论】:

    标签: ruby command-line rspec syntax


    【解决方案1】:

    您不能在命令行上配置 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-configuration和这里https://relishapp.com/rspec/rspec-mocks/docs/old-syntax/stub

    【讨论】:

      猜你喜欢
      • 2011-06-28
      • 1970-01-01
      • 2016-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-30
      相关资源
      最近更新 更多