ruby – 如何计算过滤的RSpec示例:聚焦在git钩子中?
发布时间:2020-12-17 03:29:37 所属栏目:百科 来源:网络整理
导读:我正在尝试编写一个 Git预提交钩子,如果有一个标记为:focus的示例,则不会让用户提交. 使用RSpec的API(即使它是私有的,也没关系),有没有办法找到带有:焦点过滤器的例子数量? 我找到了example_count-instance_method.它可能很有用,但我不确定如何从外部脚本
我正在尝试编写一个
Git预提交钩子,如果有一个标记为:focus的示例,则不会让用户提交.
使用RSpec的API(即使它是私有的,也没关系),有没有办法找到带有:焦点过滤器的例子数量? 我找到了example_count-instance_method.它可能很有用,但我不确定如何从外部脚本调用它. 解决方法
Here is一个
Overcommit pre_commit钩子,使用RSpecs私有API来查找规格:焦点过滤器:
require 'rspec' module Overcommit module Hook module PreCommit # NOTE: This makes use of many methods from RSpecs private API. class EnsureFocusFreeSpecs < Base def configure_rspec(applicable_files) RSpec.configure do |config| config.inclusion_filter = :focus config.files_or_directories_to_run = applicable_files config.inclusion_filter.rules config.requires = %w(spec_helper rails_helper) config.load_spec_files end end def run configure_rspec(applicable_files) return :pass if RSpec.world.example_count.zero? files = RSpec.world.filtered_examples.reject {|_k,v| v.empty?}.keys.map(&:file_path).uniq [:fail,"Trying to commit focused spec(s) in:nt#{files.join("nt")}"] end end end end end (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- VB.net学习笔记(二十五)Threading 命名空间
- c# – Monotouch应用程序中的线程数
- cocos2d-x初探学习笔记(20)--物理引擎box2d(2)
- c# – 为什么autofac会重复处理我的一次性用品?
- objective-c – 如何在InterfaceBuilder中显示自定义UIView
- c# – AppointmentManager.RequestStoreAsync在Windows Pho
- c# – 在visual studio中运行作为资源添加的exe文件
- c – 使用QueryPerformanceCounter()向后运行的时间
- ios – 自定义UINavigationBar可在模拟器上运行,但不适用于
- xml – WiX安装程序:使用xslt with heat.exe来更新属性