Created
February 13, 2018 05:47
-
-
Save myronmarston/c619133188f9df451b820fa45b400959 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 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
module IncrementAndDecrement | |
def increment(&block) | |
matcher = change(&block).by(1) | |
RSpec::Matchers::AliasedMatcher.new(matcher, lambda do |desc| | |
desc.gsub("changed", "incremented").gsub("change", "increment") | |
end) | |
end | |
def decrement(&block) | |
matcher = change(&block).by(-1) | |
RSpec::Matchers::AliasedMatcher.new(matcher, lambda do |desc| | |
desc.gsub("changed", "decremented").gsub("change", "decrement").gsub("-", "") | |
end) | |
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
Brilliant! That's a big improvement, thank you Myron! Post updated.