Skip to content

Instantly share code, notes, and snippets.

@dgreenway
Created September 9, 2014 06:30
Show Gist options
  • Save dgreenway/a9b1757c5e465c413de6 to your computer and use it in GitHub Desktop.
Save dgreenway/a9b1757c5e465c413de6 to your computer and use it in GitHub Desktop.
Adds a property to a class instance and redefines the method we want to check to update the property which we can then check
describe 'tests the thing'
it 'tests the thing' do
foo = ClassUnderTest.new
# monkeypatch an attribute onto our class
class << foo
attr_accessor :the_thing_was_called
end
# redefine the the_thing method
def fa.the_thing
self.the_thing_was_called = true
end
foo.some_method_that_calls_the_thing
assert foo.the_thing_was_called
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment