├── .gitignore ├── .rspec ├── .travis.yml ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── Gemfile ├── Gemfile.lock ├── LICENSE.txt ├── README.md ├── Rakefile ├── assets └── logo.png ├── lib ├── sane_patch.rb └── sane_patch │ └── version.rb ├── sane_patch.gemspec └── spec ├── sane_patch_spec.rb └── spec_helper.rb /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /.yardoc 3 | /_yardoc/ 4 | /coverage/ 5 | /doc/ 6 | /pkg/ 7 | /spec/reports/ 8 | /tmp/ 9 | 10 | # rspec failure tracking 11 | .rspec_status 12 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --format documentation 2 | --color 3 | --require spec_helper 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | sudo: false 3 | language: ruby 4 | cache: bundler 5 | rvm: 6 | - 2.6.3 7 | - ruby-head 8 | 9 | matrix: 10 | fast_finish: true 11 | allow_failures: 12 | - rvm: ruby-head 13 | 14 | before_install: 15 | - gem update --system 16 | - gem install bundler -v 2.0.1 17 | 18 | script: 19 | - bundle exec rspec 20 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | All notable changes to this project will be documented in this file. 3 | 4 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 5 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 6 | 7 | ## [1.0.0] - 2020-02-09 8 | No Changes. 9 | 10 | ## [0.2.0] - 2019-06-25 11 | ### Added 12 | - Added test-suite covering existing functionality by [@PikachuEXE](https://github.com/PikachuEXE) 13 | - Added the ability to specify more complex version constraints, we now support all constraints supported by [`RubyGems`](http://docs.seattlerb.org/rubygems/Gem/Requirement.html) thanks to the work of [@PikachuEXE](https://github.com/PikachuEXE) and [@jrochkind](https://github.com/jrochkind). 14 | 15 | ### Changed 16 | - Fix Typo in code example used in README. 17 | - Fix Typo in `gemspec` description. 18 | - Use custom `SanePatch::Errors::GemAbsent` instead of `ArgumentError` when a unloaded gem is patched. `SanePatch::Errors::GemAbsent` inherits `ArgumentError`. 19 | - Use custom `SanePatch::Errors::IncompatibleVersion` instead of `RuntimeError` when a loaded gem does not meet the requirements of a patch. For backwards compatibility reasons `SanePatch::Errors::IncompatibleVersion` inherits `RuntimeError`. 20 | 21 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, gender identity and expression, level of experience, 9 | nationality, personal appearance, race, religion, or sexual identity and 10 | orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at hello@joel.am. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at [http://contributor-covenant.org/version/1/4][version] 72 | 73 | [homepage]: http://contributor-covenant.org 74 | [version]: http://contributor-covenant.org/version/1/4/ 75 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | # Specify your gem's dependencies in sane_patch.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | PATH 2 | remote: . 3 | specs: 4 | sane_patch (1.0.0) 5 | 6 | GEM 7 | remote: https://rubygems.org/ 8 | specs: 9 | diff-lcs (1.3) 10 | rake (13.0.1) 11 | rspec (3.7.0) 12 | rspec-core (~> 3.7.0) 13 | rspec-expectations (~> 3.7.0) 14 | rspec-mocks (~> 3.7.0) 15 | rspec-core (3.7.0) 16 | rspec-support (~> 3.7.0) 17 | rspec-expectations (3.7.0) 18 | diff-lcs (>= 1.2.0, < 2.0) 19 | rspec-support (~> 3.7.0) 20 | rspec-mocks (3.7.0) 21 | diff-lcs (>= 1.2.0, < 2.0) 22 | rspec-support (~> 3.7.0) 23 | rspec-support (3.7.0) 24 | 25 | PLATFORMS 26 | ruby 27 | 28 | DEPENDENCIES 29 | bundler (~> 2.0) 30 | rake (~> 13.0) 31 | rspec (~> 3.0) 32 | sane_patch! 33 | 34 | BUNDLED WITH 35 | 2.0.2 36 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2019 Joel Ambass 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # SanePatch [![Gem Version](https://badge.fury.io/rb/sane_patch.svg)](https://badge.fury.io/rb/sane_patch) ![Gem Downloads](https://img.shields.io/gem/dt/sane_patch) [![Build Status](https://travis-ci.com/Jcambass/sane_patch.svg?branch=master)](https://travis-ci.com/Jcambass/sane_patch) 4 | 5 | SanePatch is a simple and non intrusive helper that aims to make monkey patching a little bit safer. 6 | 7 | It achieves this by only applying your patches to a specific version of a gem and raising a exception if the gem version changed. This means that you will always double check that your patches still work after upgrading gems. No surprises anymore! 8 | 9 | ## But wait.. Isn't monkey patching bad? 10 | 11 | As with many things in life there is no pure good or bad. Monkey patching can be dangerous in certain situations and should be avoided sometimes but there are reasons to use it. 12 | 13 | Good reasons to monkey patch a gem could be: 14 | - Fixing a bug in a broken gem until a new version of it is released. 15 | - Performance optimizing a specific method of a gem that is used in a hot code path. 16 | 17 | ## Installation 18 | 19 | Add this line to your application's Gemfile: 20 | 21 | ```ruby 22 | gem 'sane_patch', '~> 1.0' 23 | ``` 24 | 25 | And then execute: 26 | 27 | $ bundle 28 | 29 | ## Usage 30 | 31 | The usage of SanePatch is straight forward: 32 | 33 | 34 | ```ruby 35 | SanePatch.patch('', '') do 36 | # Apply your patches here the same way as usual. 37 | end 38 | ``` 39 | 40 | A more specific example: 41 | 42 | ```ruby 43 | Greeter.greet # => 'Hello' 44 | 45 | # Let's patch the `Greeter.greet` method to output 'Hello Folks' 46 | module GreeterPatch 47 | def greet 48 | "#{super} Folks" 49 | end 50 | end 51 | 52 | # We currently have version 1.1.0 of the greeter gem 53 | SanePatch.patch('greeter', '1.1.0') do 54 | Greeter.prepend(GreeterPatch) 55 | end 56 | 57 | Greeter.greet # => 'Hello Folks' 58 | ``` 59 | 60 | If somebody updates the gem version the patch will raise as soon as its code path is executed: 61 | ``` 62 | SanePatch::Errors::IncompatibleVersion: 63 | It looks like the greeter gem was upgraded. 64 | There are patches in place that need to be verified. 65 | Make sure that the patch at initializers/greeter_patch.rb:8 is still needed and working. 66 | ``` 67 | 68 | Setting the `raise_error` keyword argument to `false` will skip the execution of the block but will not raise an error. (The default value for the keyword is `true`.) 69 | 70 | ### Complex version constraints 71 | 72 | SanePatch supports all [version constraints](http://docs.seattlerb.org/rubygems/Gem/Requirement.html) you know and love from RubyGems. 73 | 74 | ```ruby 75 | SanePatch.patch('greeter', '~> 1.1.0') { # your patch } 76 | SanePatch.patch('greeter', '> 1.1.0') { # your patch } 77 | SanePatch.patch('greeter', '< 1.1.0') { # your patch } 78 | ``` 79 | 80 | It even supports version ranges based on multiple constraints: 81 | 82 | ```ruby 83 | SanePatch.patch('greeter', '> 1.0.0', '< 1.1.0') { # your patch } 84 | ``` 85 | 86 | This is especially useful if you patch a bug where you know the affected gem versions. 87 | 88 | ### Providing additional information 89 | 90 | If you patch a known bug in a gem it might be useful to provide additional information why the patch is needed and when it can be removed. 91 | 92 | ```ruby 93 | Greeter.silence # => nil 94 | 95 | module GreeterPatch 96 | def silence 97 | '' 98 | end 99 | end 100 | 101 | details = <<-MSG 102 | The `silence` method should output an empty string rather than nil. 103 | This is a known issue and will be fixed in the next release. 104 | See: https://github.com/Jcambass/greeter/issues/45 105 | MSG 106 | 107 | SanePatch.patch('greeter', '1.1.0', details: details) do 108 | Greeter.prepend(GreeterPatch) 109 | end 110 | 111 | Greeter.silence # => '' 112 | ``` 113 | 114 | The additionally provided details will also show up in the exception message. 115 | 116 | ``` 117 | SanePatch::Errors::IncompatibleVersion: 118 | It looks like the greeter gem was upgraded. 119 | There are patches in place that need to be verified. 120 | Make sure that the patch at initializers/greeter_patch.rb:8 is still needed and working. 121 | Details: 122 | The `silence` method should output an empty string rather than nil. 123 | This is a known issue and will be fixed in the next release. 124 | See: https://github.com/Jcambass/greeter/issues/45 125 | ``` 126 | 127 | ### Logging support 128 | 129 | The `logger` keyword argument can be used to supply a logger instance. SanePatch will pass the exception message to that object's `#warn` method when the version constraint is not satisfied: 130 | 131 | ```ruby 132 | SanePatch.patch('greeter', '1.1.0', logger: Logger.new(STDOUT)) { # your patch } 133 | ``` 134 | 135 | ## Contributing 136 | 137 | Bug reports and pull requests are welcome on GitHub at https://github.com/Jcambass/sane_patch. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct. 138 | 139 | ## License 140 | 141 | The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). 142 | 143 | ## Code of Conduct 144 | 145 | Everyone interacting in the SanePatch project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/Jcambass/sane_patch/blob/master/CODE_OF_CONDUCT.md). 146 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | require "rspec/core/rake_task" 3 | 4 | RSpec::Core::RakeTask.new(:spec) 5 | 6 | task :default => :spec 7 | -------------------------------------------------------------------------------- /assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jcambass/sane_patch/fb63c1953beafdb204360f78293ce337cbc48fb6/assets/logo.png -------------------------------------------------------------------------------- /lib/sane_patch.rb: -------------------------------------------------------------------------------- 1 | require "sane_patch/version" 2 | 3 | module SanePatch 4 | module Errors 5 | GemAbsent = Class.new(ArgumentError) 6 | IncompatibleVersion = Class.new(RuntimeError) 7 | end 8 | 9 | def self.patch(gem_name, *requirements, details: nil, raise_error: true, logger: nil) 10 | gem_spec = Gem.loaded_specs[gem_name] 11 | raise Errors::GemAbsent, "Can't patch unloaded gem #{gem_name}" unless gem_spec 12 | 13 | gem_requirement = Gem::Requirement.create(requirements) 14 | if gem_requirement.satisfied_by?(gem_spec.version) 15 | yield 16 | else 17 | message = <<~ERROR 18 | It looks like the #{gem_name} gem was upgraded. 19 | There are patches in place that need to be verified. 20 | Make sure that the patch at #{caller_locations.first} is still needed and working. 21 | ERROR 22 | message += "Details:\n#{details}" if details 23 | 24 | logger.warn(message) if logger 25 | 26 | raise Errors::IncompatibleVersion, message if raise_error 27 | end 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /lib/sane_patch/version.rb: -------------------------------------------------------------------------------- 1 | module SanePatch 2 | VERSION = "1.0.0" 3 | end 4 | -------------------------------------------------------------------------------- /sane_patch.gemspec: -------------------------------------------------------------------------------- 1 | 2 | lib = File.expand_path("../lib", __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | require "sane_patch/version" 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = "sane_patch" 8 | spec.version = SanePatch::VERSION 9 | spec.authors = ["Joel Ambass"] 10 | spec.email = ["hello@joel.am"] 11 | 12 | spec.summary = %q{Making monkey patches sane again} 13 | spec.description = %q{SanePatch will prevent gem upgrades from silently breaking your monkey patches.} 14 | spec.homepage = "https://github.com/Jcambass/sane_patch" 15 | spec.license = "MIT" 16 | 17 | # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host' 18 | # to allow pushing to a single host or delete this section to allow pushing to any host. 19 | if spec.respond_to?(:metadata) 20 | spec.metadata["homepage_uri"] = spec.homepage 21 | spec.metadata["source_code_uri"] = "https://github.com/Jcambass/sane_patch" 22 | else 23 | raise "RubyGems 2.0 or newer is required to protect against " \ 24 | "public gem pushes." 25 | end 26 | 27 | # Specify which files should be added to the gem when it is released. 28 | # The `git ls-files -z` loads the files in the RubyGem that have been added into git. 29 | spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do 30 | `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|assets)/}) } 31 | end 32 | spec.bindir = "exe" 33 | spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } 34 | spec.require_paths = ["lib"] 35 | 36 | spec.add_development_dependency "bundler", "~> 2.0" 37 | spec.add_development_dependency "rake", "~> 13.0" 38 | spec.add_development_dependency "rspec", "~> 3.0" 39 | end 40 | -------------------------------------------------------------------------------- /spec/sane_patch_spec.rb: -------------------------------------------------------------------------------- 1 | require 'logger' 2 | 3 | RSpec.describe SanePatch do 4 | it "has a version number" do 5 | expect(SanePatch::VERSION).not_to be nil 6 | end 7 | 8 | describe ".patch" do 9 | context "when gem is not installed" do 10 | it "raises error for non-existing gem" do 11 | expect do 12 | SanePatch.patch('some_gem', "0.0.1") 13 | end.to raise_error(SanePatch::Errors::GemAbsent) 14 | end 15 | end 16 | 17 | context "when gem is installed", :aggregate_failures do 18 | it "raises error for incompatible version" do 19 | with_loaded_gems('some_gem' => "1.0.1") do 20 | expect { |b| SanePatch.patch('some_gem', "0.0.1", &b) }.to engage_guard 21 | end 22 | end 23 | 24 | it "raises error for incompatible version constraint" do 25 | with_loaded_gems('some_gem' => "1.0.1") do 26 | expect { |b| SanePatch.patch('some_gem', "~> 0.0.1", &b) }.to engage_guard 27 | end 28 | end 29 | 30 | it "raises error for incompatible version constraints" do 31 | with_loaded_gems('some_gem' => "1.0.1") do 32 | expect { |b| SanePatch.patch('some_gem', ">= 0.0.1", "< 1.0.0", &b) }.to engage_guard 33 | end 34 | end 35 | 36 | context "when configured to not raise an error" do 37 | it "doesn't raise an error for incompatible version" do 38 | with_loaded_gems('some_gem' => "1.0.1") do 39 | expect { |b| SanePatch.patch('some_gem', "0.0.1", raise_error: false, &b) }.to engage_guard_no_raise 40 | end 41 | end 42 | 43 | it "doesn't raise an error for incompatible version constraint" do 44 | with_loaded_gems('some_gem' => "1.0.1") do 45 | expect { |b| SanePatch.patch('some_gem', "~> 0.0.1", raise_error: false, &b) }.to engage_guard_no_raise 46 | end 47 | end 48 | 49 | it "doesn't raise an error for incompatible version constraints" do 50 | with_loaded_gems('some_gem' => "1.0.1") do 51 | expect { |b| SanePatch.patch('some_gem', ">= 0.0.1", "< 1.0.0", raise_error: false, &b) }.to engage_guard_no_raise 52 | end 53 | end 54 | end 55 | 56 | context "when configured with a logger" do 57 | let(:logger) { instance_double(Logger) } 58 | 59 | it "logs a warning for incompatible version" do 60 | with_loaded_gems('some_gem' => "1.0.1") do 61 | expect(logger).to receive(:warn).with(/some_gem/) 62 | SanePatch.patch('some_gem', "0.0.1", logger: logger, raise_error: false) { raise "Won't execute" } 63 | end 64 | end 65 | 66 | it "logs a warning for incompatible version constraint" do 67 | with_loaded_gems('some_gem' => "1.0.1") do 68 | expect(logger).to receive(:warn).with(/some_gem/) 69 | SanePatch.patch('some_gem', "0.0.1", logger: logger, raise_error: false) { raise "Won't execute" } 70 | end 71 | end 72 | 73 | it "logs a warning for incompatible version constraints" do 74 | with_loaded_gems('some_gem' => "1.0.1") do 75 | expect(logger).to receive(:warn).with(/some_gem/) 76 | SanePatch.patch('some_gem', "0.0.1", logger: logger, raise_error: false) { raise "Won't execute" } 77 | end 78 | end 79 | end 80 | 81 | it "execute block for compatible version" do 82 | with_loaded_gems('some_gem' => "1.0.1") do 83 | expect { |b| SanePatch.patch('some_gem', "1.0.1", &b) }.not_to engage_guard 84 | end 85 | end 86 | 87 | it "execute block for compatible version constraint" do 88 | with_loaded_gems('some_gem' => "1.0.1") do 89 | expect { |b| SanePatch.patch('some_gem', "~> 1.0.0", &b) }.not_to engage_guard 90 | end 91 | end 92 | 93 | it "execute block for compatible version constraints" do 94 | with_loaded_gems('some_gem' => "1.0.1") do 95 | expect { |b| SanePatch.patch('some_gem', ">= 1.0.0", "< 1.1.0", &b) }.not_to engage_guard 96 | end 97 | end 98 | end 99 | end 100 | end 101 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require "bundler/setup" 2 | require "sane_patch" 3 | require 'rspec/expectations' 4 | 5 | RSpec.configure do |config| 6 | # Enable flags like --only-failures and --next-failure 7 | config.example_status_persistence_file_path = ".rspec_status" 8 | 9 | # Disable RSpec exposing methods globally on `Module` and `main` 10 | config.disable_monkey_patching! 11 | 12 | config.expect_with :rspec do |c| 13 | c.syntax = :expect 14 | c.include_chain_clauses_in_custom_matcher_descriptions = true 15 | end 16 | end 17 | 18 | def with_loaded_gems(gem_name_version_hash) 19 | gem_name_version_hash.each_pair do |gem_name, gem_version| 20 | allow(Gem.loaded_specs).to receive(:[]).with(gem_name).and_return( 21 | double("Fake Gemspec for #{gem_name}", version: Gem::Version.new(gem_version)) 22 | ) 23 | end 24 | 25 | yield 26 | end 27 | 28 | RSpec::Matchers.define :engage_guard do 29 | match do |actual| 30 | yielded = false 31 | expect { 32 | actual.call(Proc.new { yielded = true }) 33 | }.to raise_error(SanePatch::Errors::IncompatibleVersion) 34 | expect(yielded).to be_falsey 35 | end 36 | 37 | match_when_negated do |actual| 38 | yielded = false 39 | actual.call(Proc.new { yielded = true }) 40 | expect(yielded).to be_truthy 41 | end 42 | 43 | supports_block_expectations 44 | end 45 | 46 | RSpec::Matchers.define :engage_guard_no_raise do 47 | match do |actual| 48 | yielded = false 49 | expect { 50 | actual.call(Proc.new { yielded = true }) 51 | }.to_not raise_error 52 | expect(yielded).to be_falsey 53 | end 54 | 55 | supports_block_expectations 56 | end 57 | --------------------------------------------------------------------------------