[mocha-developer] Howto find out, a function was called

Rainer Jung rainer.jung at gmail.com
Thu Mar 15 14:36:15 EDT 2007


Hello there!

I just started with Mocha (great job, by the way), and want to solve a
problem, perhaps you can give me a hint.

I have a Observer (yes, in Rails), and want to test, that this
observer does (or does not) call a special method on the observed
object.
In this example, the object has a sync-method, that shall be called
before_update.
The Observer looks like
  class BlaObserver < Observer
    @@sync = true
    def before_save(object)
      object.sync if @@sync
    end
    def self.ignore
      before = @@sync
      @@sync = false
      yield
      @@sync = before
    end
  end
Now i want to test, if the method sync is called, if i call
  BlaObserver.ignore do
    object.save
  end
Do you have an idea?

Regards, Rainer


More information about the mocha-developer mailing list