Class: Mongoid::Matchers::HaveCallbackMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/matchers/callbacks.rb

Constant Summary collapse

KINDS =
%w[ before around after ]

Instance Method Summary collapse

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

#descriptionObject



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_shouldObject



39
40
41
# File 'lib/matchers/callbacks.rb', line 39

def failure_message_for_should
  failure_message( true )
end

#failure_message_for_should_notObject



43
44
45
# File 'lib/matchers/callbacks.rb', line 43

def failure_message_for_should_not
  failure_message( false )
end

#matches?(klass) ⇒ Boolean

Returns:

  • (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.options[: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