Class: TimelineFu::Matchers::FireEvent
- Inherits:
-
Object
- Object
- TimelineFu::Matchers::FireEvent
- Defined in:
- lib/timeline_fu/matchers.rb
Instance Method Summary collapse
- #defines_callback_method? ⇒ Boolean
- #description ⇒ Object
- #expectation ⇒ Object
- #failure_message ⇒ Object
-
#initialize(event_type, opts = {}) ⇒ FireEvent
constructor
A new instance of FireEvent.
- #matches?(subject) ⇒ Boolean
- #negative_failure_message ⇒ Object
- #setups_up_callback? ⇒ Boolean
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
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 |
#description ⇒ Object
36 37 38 |
# File 'lib/timeline_fu/matchers.rb', line 36 def description "fire a #{@event_type} event" end |
#expectation ⇒ Object
40 41 42 |
# File 'lib/timeline_fu/matchers.rb', line 40 def expectation expected = "#{@subject.name} to #{description}" end |
#failure_message ⇒ Object
44 45 46 |
# File 'lib/timeline_fu/matchers.rb', line 44 def "Expected #{expectation} (#{@missing})" end |
#matches?(subject) ⇒ 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_message ⇒ Object
48 49 50 |
# File 'lib/timeline_fu/matchers.rb', line 48 def "Did not expect #{expectation}" end |
#setups_up_callback? ⇒ 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 |