Class: Mongoid::Matchers::HaveCallbackMatcher
- Inherits:
-
Object
- Object
- Mongoid::Matchers::HaveCallbackMatcher
- Defined in:
- lib/matchers/callbacks.rb
Constant Summary collapse
- KINDS =
%w[ before around after ]
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message_for_should ⇒ Object
- #failure_message_for_should_not ⇒ Object
-
#initialize(*args) ⇒ HaveCallbackMatcher
constructor
A new instance of HaveCallbackMatcher.
- #matches?(klass) ⇒ Boolean
- #on(action) ⇒ Object
Constructor Details
#initialize(*args) ⇒ HaveCallbackMatcher
Returns a new instance of HaveCallbackMatcher.
6 7 8 |
# File 'lib/matchers/callbacks.rb', line 6 def initialize( *args ) @methods = args || [] end |
Instance Method Details
#description ⇒ Object
47 48 49 50 51 52 |
# File 'lib/matchers/callbacks.rb', line 47 def description msg = "call #{@methods.join(", ")}" msg << " #{@kind} #{@operation}" if @operation msg << " on #{@on}" if @on msg end |
#failure_message_for_should ⇒ Object
39 40 41 |
# File 'lib/matchers/callbacks.rb', line 39 def ( true ) end |
#failure_message_for_should_not ⇒ Object
43 44 45 |
# File 'lib/matchers/callbacks.rb', line 43 def ( false ) end |
#matches?(klass) ⇒ Boolean
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/matchers/callbacks.rb', line 10 def matches?( klass ) return false unless @kind return false if @no_op = !klass.class.respond_to?( :"_#{@operation}_callbacks" ) @guess = nil @methods.each do |method| filter = klass.class.send( :"_#{@operation}_callbacks" ).detect do |c| @guess = c if c.filter == method c.filter == method and c.kind == @kind and c.[:on] == @on end return false unless filter end end |
#on(action) ⇒ Object
34 35 36 37 |
# File 'lib/matchers/callbacks.rb', line 34 def on( action ) @on = action self end |