mardi 5 mai 2015

How to stub whole module using Mocha?

I have a complex module used in my implementation with some functions in it.

module A
  def function some_params
    #returns some chain object
  end
end

#implementation

class SomeImplementation
  def some_function some_params
    A.function(some_params_other).function1 
  end
end

I want to stub it by my class:

class AStub
  def function params
    #rely on params
    do_something_else_return_same_object
  end

  def function1
    other_do
  end
end

How i can do it? In particular how to replace A to being my class using Mocha. Any thoughts? I can't do that:

A.stubs(:function)

because there is no way to catch first parameters (i need them to define next behavior).

Aucun commentaire:

Enregistrer un commentaire