如何在rspec中获取与before(:context)关联的标记?

6ojccjat  于 2021-09-29  发布在  Java
关注(0)|答案(1)|浏览(204)

我有一个样本

context 'test case', :tag => true do
end

在我的spec_helper.rb中,我想跳过基于上下文中存在的标记的测试,但我无法获取上下文元数据

RSpec.configure do |config|
  config.before(:context) do |example|
    // code to filter based upon tags
  end
end
xxb16uws

xxb16uws1#

你可以这样匹配它

config.before(:context, tag: true)

只有在标记被激活时,才会触发钩子 true .
您也可以在中访问它 example.metadata :

config.before(:context) do |example| 
  if example.metadata[:tag]
    do_sth
  else
    do_sth_else
  end
end

在钩子/过滤器中阅读更多信息:https://relishapp.com/rspec/rspec-core/v/3-10/docs/hooks/filters
和元数据部分:https://relishapp.com/rspec/rspec-core/v/3-10/docs/metadata/user-defined-metadata

相关问题