Skip to content

Instantly share code, notes, and snippets.

@myronmarston
Created February 13, 2018 05:47
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save myronmarston/c619133188f9df451b820fa45b400959 to your computer and use it in GitHub Desktop.
Save myronmarston/c619133188f9df451b820fa45b400959 to your computer and use it in GitHub Desktop.
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
@tcopeland
Copy link

Brilliant! That's a big improvement, thank you Myron! Post updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment