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 :bar
end
难道这种可能性是多少,或者你是否想到其他方式来取得这一功能?