Forked from myronmarston/increment_and_decrement.rb
Last active
June 6, 2019 14:49
-
-
Save RobertAudi/8d0fc876eeee45d27fba9baa5412b9be to your computer and use it in GitHub Desktop.
Alternate implementation for https://thomasleecopeland.com/2018/02/12/increment-decrement-matcher.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
RSpec::Matchers.alias_matcher :increment, :change do |desc| | |
desc.gsub("changed", "incremented").gsub("change", "increment") | |
end | |
RSpec::Matchers.alias_matcher :decrement, :change do |desc| | |
desc.gsub("changed", "decremented").gsub("change", "decrement").gsub("-", "") | |
end | |
module IncrementAndDecrement | |
def increment(by: 1, &block) | |
super(&block).by(by) | |
end | |
def decrement(by: 1, &block) | |
super(&block).by(-by) | |
end | |
end | |
RSpec.configure do |c| | |
c.include IncrementAndDecrement | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment