如何配置 spec_helper 文件以仅获取与 Rspec 中的 before(:context) 关联的标签?
How to configure spec_helper file to get only tags that are associated with before(:context) in Rspec?
我有一个sample_spec.rb
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
你可以这样搭配
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
在 Hooks/filters 此处阅读更多相关信息: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
我有一个sample_spec.rb
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
你可以这样搭配
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
在 Hooks/filters 此处阅读更多相关信息: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