【问题标题】:Rspec (run when flag is set)Rspec(设置标志时运行)
【发布时间】:2019-07-15 19:41:31
【问题描述】:

如何仅在设置标志时运行 rspec 测试?

我正在使用 Stripe-Ruby-Mock,他们使用 live 标志。但是,我不希望在未设置 -t live 时运行测试。

bundle exec rspec -t live spec

it "should run rspec test, only when live is true", live: true do
  expect('value').to eq('value')
end

目前,我的测试在设置-t live 和未设置时运行。

【问题讨论】:

    标签: rspec rspec-rails rspec3


    【解决方案1】:

    配置 RSpec 以在您的 spec_helper.rb 中使用 #filter_run_excluding 默认过滤掉该标签:

    config.filter_run_excluding live: true
    

    这样它们只会在您在命令行上指定标签时运行。

    【讨论】:

      【解决方案2】:

      你可以设置一个环境变量:

      LIVE=true bundle exec rspec 规范

      然后在您的代码中,您可以使用 ENV['LIVE'] 作为if(conditional filter)。 详情请查看conditional filters

      【讨论】:

        猜你喜欢
        • 2023-03-25
        • 1970-01-01
        • 2012-08-20
        • 1970-01-01
        • 2015-09-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多