Skip to content

Instantly share code, notes, and snippets.

@tomafro
Forked from mbleigh/Alternative.rb
Created September 2, 2008 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomafro/8397 to your computer and use it in GitHub Desktop.
Save tomafro/8397 to your computer and use it in GitHub Desktop.
# I hear that aliasing lambda is bad, but this is
# much more readable...
alias :this_block :lambda
this_block{ @this.destroy }.should change(Thing, :count).by(-1)
# (tomafro) I've done this for ages, only using doing rather than this_block:
alias :doing, :lambda
doing{ @this.destroy }.should change(Thing, :count).by(-1)
#Throw this in spec helper
def block_should(matcher, &block)
block.should matcher
end
def block_should_not(matcher, &block)
block.should_not matcher
end
#Use it like this
block_should change(Thing, :count).by(-1) do
@thing.destroy
end
#Which is just a little cleaner version of this
lambda do
@thing.destroy
end.should change(Thing, :count).by(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment