Class: TimelineFu::Matchers::FireEvent

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

Instance Method Summary collapse

Constructor Details

#initialize(event_type, opts = {}) ⇒ FireEvent

Returns a new instance of FireEvent.



4
5
6
7
8
# File 'lib/timeline_fu/matchers.rb', line 4

def initialize(event_type, opts = {})
  @event_type = event_type
  @opts = opts
  @method = :"fire_#{@event_type}_after_#{@opts[:on]}"
end

Instance Method Details

#defines_callback_method?Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
22
23
# File 'lib/timeline_fu/matchers.rb', line 16

def defines_callback_method?
  if @subject.instance_methods.include?(@method.to_s)
    true
  else
    @missing = "#{@subject.name} does not respond to #{@method}"
    false
  end
end

#descriptionObject



36
37
38
# File 'lib/timeline_fu/matchers.rb', line 36

def description
  "fire a #{@event_type} event"
end

#expectationObject



40
41
42
# File 'lib/timeline_fu/matchers.rb', line 40

def expectation
  expected = "#{@subject.name} to #{description}"
end

#failure_messageObject



44
45
46
# File 'lib/timeline_fu/matchers.rb', line 44

def failure_message
  "Expected #{expectation} (#{@missing})"
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
14
# File 'lib/timeline_fu/matchers.rb', line 10

def matches?(subject)
  @subject = subject

  defines_callback_method? && setups_up_callback?
end

#negative_failure_messageObject



48
49
50
# File 'lib/timeline_fu/matchers.rb', line 48

def negative_failure_message
  "Did not expect #{expectation}"
end

#setups_up_callback?Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
33
34
# File 'lib/timeline_fu/matchers.rb', line 25

def setups_up_callback?
  callback_chain_name = "after_#{@opts[:on]}_callback_chain"
  callback_chain = @subject.send(callback_chain_name)
  if callback_chain.any? {|chain| chain.method == @method }
    true
  else
    @missing = "does setup after #{@opts[:on]} callback for #{@method}"
    false
  end
end