Mocking/stubbing a method that's included from “instance.extend(DecoratorModule)”

Sunday, October 9, 2011

I use a decorator module that get's included in a model instance (through the "extends" method). So for example :
module Decorator
  def foo
  end
end
class Model < ActiveRecord::Base
end
class ModelsController < ApplicationController
  def bar
    @model = Model.find(params[:id])
    @model.extend(Decorator)
    @model.foo
  end
end
Then I would like in the tests to do the following (using Mocha) :
test "bar" do
  Model.any_instance.expects(:foo).returns("bar")
  get :barend 
Is this possible somehow, or do you have in mind any other way to get this functionality???

Stack Overflow question

4 comments:

  • Post a Comment