【问题标题】:RSpec: get list of all examples that will be runRSpec:获取将运行的所有示例的列表
【发布时间】:2019-03-27 14:19:28
【问题描述】:

我正在使用 RSpec 3。

before(:suite) 块中,想要获取(嵌套?)将在当前规范运行中运行的所有示例的列表(即,当给出路径时),以便我可以扫描它们的所有元数据。

背景:我希望能够推断出是否存在capybara规范,如果是的话,启动一个前端服务器。

【问题讨论】:

    标签: rspec rspec3


    【解决方案1】:

    你不一定要预先做,when_first_matching_example_defined hook 会运行指定的代码

    RSpec.configure do |config|
      config.when_first_matching_example_defined(:capybara) do
        start_server
      end
    end
    
    RSpec.describe do
      describe 'non-capybara' do
        # when running this example group only, `start_server` won't be called
      end
    
      describe 'capybara', :capybara do
        # when RSpec gets to this example group, it will call `start_server`
      end
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-18
      • 1970-01-01
      • 2018-01-20
      • 1970-01-01
      • 1970-01-01
      • 2022-12-12
      相关资源
      最近更新 更多