大佬教程收集整理的这篇文章主要介绍了ruby – 如何在RSpec中的before(:suite)/ before(:all)钩子中访问标记过滤器?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
命令行
rspec --tag use_ff
RSpec配置
RSpec.configure do |config| config.before :suite,type: :feature do # how do I check if use_ff filter was specified in the command line? if filter[:use_ff] use_SELEnium else use_poltergeist end end end
在before(:suitE)钩子中,我想访问config中命令行中指定的标记过滤器.
根据rspec-core代码库,包含标记过滤器存储在RSpec.configuration的inclusion_filter中.从理论上讲,我应该能够按如下方式访问它们:
RSpec.configure do |config| config.before :suite,type: :feature do if config.filter[:use_ff] # filter is an alias for inclusion_filter use_SELEnium else use_poltergeist end end end
但是,出于某种原因,即使从命令行传递标记,我也会得到一个空哈希.
RSpec::Core::InclusionRules
.在它的超类
RSpec::Core::FilterRules
中,我们看到它有一个访问器.rules,它返回一个标签的哈希,所以你可以做,例如,RSpec.configure do |config| config.before(:suitE) do $running_only_examples_tagged_foo = config.filter.rules[:foo] end end describe "Something" do it "knows we're running only examples tagged foo",:foo do expect($running_only_examples_tagged_foo).to be_truthy # passes end end
(我正在使用RSpec 3.4.)
以上是大佬教程为你收集整理的ruby – 如何在RSpec中的before(:suite)/ before(:all)钩子中访问标记过滤器?全部内容,希望文章能够帮你解决ruby – 如何在RSpec中的before(:suite)/ before(:all)钩子中访问标记过滤器?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。