shoulda_macros/units.rb
def should_callback(*meths)
      if meths.size < 2
        raise(RuntimeError, "Expecting legal callback type as last argument.")
      end
    
      klass = self.name.gsub(/Test$/, '').constantize
      callback_type = meths.delete(meths.last).to_s
        
      meths.each do |meth|
        have_certain_callback = "call ##{meth} #{callback_type.to_s.gsub(/_/, ' ')}"
        should have_certain_callback do
          existing_callbacks = klass.send(callback_type)
          result = existing_callbacks.detect { |callback| callback.method == meth.to_sym }
          assert_not_nil result, "##{meth} is not called #{callback_type.to_s.gsub(/_/, ' ')}"
        end
      end
    end
##
#  Asserts that model defines callback for a certain method.
#
#    should_callback :foo, :after_save
#    should_callback :bar, :baz, :before_save
#
Asserts that model defines callback for a certain method.
Asserts that model defines callback for a certain method .
def should_callback(*meths)
      if meths.size < 2
        raise(RuntimeError, "Expecting legal callback type as last argument.")
      end
      klass = self.name.gsub(/Test$/, '').constantize
      callback_type = meths.delete(meths.last).to_s
      meths.each do |meth|
        have_certain_callback = "call ##{meth} #{callback_type.to_s.gsub(/_/, ' ')}"
        should have_certain_callback do
          existing_callbacks = klass.send(callback_type)
          result = existing_callbacks.detect { |callback| callback.method == meth.to_sym }
          assert_not_nil result, "##{meth} is not called #{callback_type.to_s.gsub(/_/, ' ')}"
        end
      end
    end
def should_callback ( * meths ) if meths . size < 2 raise ( RuntimeError , "Expecting legal callback type as last argument." ) end klass = self . name . gsub ( / Test$ / , '' ) . constantize callback_type = meths . delete ( meths . last ) . to_s meths . each do | meth | have_certain_callback = "call ##{meth} #{callback_type.to_s.gsub(/_/, ' ')}" should have_certain_callback do existing_callbacks = klass . send ( callback_type ) result = existing_callbacks . detect { | callback | callback . method == meth . to_sym } assert_not_nil result , "##{meth} is not called #{callback_type.to_s.gsub(/_/, ' ')}" end end end
Asserts that model defines callback for a certain method.
Asserts that model defines callback for a certain method .
meths