Re: alias_method_chain and ActiveSupport::TestCase

Frederick Cheung
Thu, 22 Oct 2009 07:40:10 -0000

On Oct 21, 7:38 pm, erik <e...-9T/GIyPsA//QT0dZR+AlfA@public.gmane.org>
wrote:
>
> i''m not sure why the alias_method_chain seems to work for test
with no
> setup method and not for one that has a setup method defined.  Any
> help would be great.

In a nutshell, because there is no reason it should. If a class
overrides the superclass implementation of a method then that
superclass implementation is not called unless the new implementation
explicitly does it. You should be able to do

def setup
  super
  ...
end

However you don''t need to do all this, because ActiveSupport::TestCase
already handles this sort of stuff. If you do

class ActiveSupport::TestCase
  def setup_with_ts
  end

  setup :setup_with_ts
end

then your method will get called at the appropriate time
(ActiveSupport sets up a callback chain that is run just before setup
is called)

Fred