Module: Motion::TestHelpers
- Defined in:
- lib/motion/test_helpers.rb
Defined Under Namespace
Classes: MockComponent
Instance Method Summary collapse
- #assert_motion(component, motion_name) ⇒ Object
- #assert_timer(component, method_name, interval) ⇒ Object
- #callback_stub(method_name = :bound) ⇒ Object
- #motion?(component, motion_name) ⇒ Boolean
- #motion_event(attributes = {}) ⇒ Object
- #process_broadcast(component, method_name, msg) ⇒ Object
- #refute_motion(component, motion_name) ⇒ Object
- #refute_timer(component, method_name) ⇒ Object
- #run_motion(component, motion_name, event = motion_event) ⇒ Object
- #timer?(component, method_name) ⇒ Boolean
Instance Method Details
#assert_motion(component, motion_name) ⇒ Object
15 16 17 |
# File 'lib/motion/test_helpers.rb', line 15 def assert_motion(component, motion_name) assert motion?(component, motion_name) end |
#assert_timer(component, method_name, interval) ⇒ Object
42 43 44 |
# File 'lib/motion/test_helpers.rb', line 42 def assert_timer(component, method_name, interval) assert_equal interval, component.periodic_timers[method_name.to_s] end |
#callback_stub(method_name = :bound) ⇒ Object
11 12 13 |
# File 'lib/motion/test_helpers.rb', line 11 def callback_stub(method_name = :bound) Motion::Callback.new(MockComponent.new, method_name) end |
#motion?(component, motion_name) ⇒ Boolean
23 24 25 |
# File 'lib/motion/test_helpers.rb', line 23 def motion?(component, motion_name) component.motions.include?(motion_name.to_s) end |
#motion_event(attributes = {}) ⇒ Object
54 55 56 57 58 |
# File 'lib/motion/test_helpers.rb', line 54 def motion_event(attributes = {}) Motion::Event.new(ActiveSupport::JSON.decode(attributes.to_json)).tap do |event| set_form_data(event, attributes) end end |
#process_broadcast(component, method_name, msg) ⇒ Object
37 38 39 40 |
# File 'lib/motion/test_helpers.rb', line 37 def process_broadcast(component, method_name, msg) callback = component.bind(method_name) component.process_broadcast(callback.broadcast, msg) end |
#refute_motion(component, motion_name) ⇒ Object
19 20 21 |
# File 'lib/motion/test_helpers.rb', line 19 def refute_motion(component, motion_name) refute motion?(component, motion_name) end |
#refute_timer(component, method_name) ⇒ Object
46 47 48 |
# File 'lib/motion/test_helpers.rb', line 46 def refute_timer(component, method_name) refute timer?(component, method_name) end |
#run_motion(component, motion_name, event = motion_event) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/motion/test_helpers.rb', line 27 def run_motion(component, motion_name, event = motion_event) if block_given? c = component.dup c.process_motion(motion_name.to_s, event) yield c else component.process_motion(motion_name.to_s, event) end end |
#timer?(component, method_name) ⇒ Boolean
50 51 52 |
# File 'lib/motion/test_helpers.rb', line 50 def timer?(component, method_name) component.periodic_timers.include?(method_name.to_s) end |