Class: Listen::Compat::Test::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/listen/compat/test/session.rb

Overview

Class for conveniently simulating interaction with Listen

Instance Method Summary collapse

Constructor Details

#initialize(wrapper_class = nil, &block) ⇒ Session

Calls the potentially blocking given block in a background thread



11
12
13
14
15
16
17
18
# File 'lib/listen/compat/test/session.rb', line 11

def initialize(wrapper_class = nil, &block)
  Wrapper.wrapper_class = wrapper_class || Listen::Compat::Test::Fake
  Wrapper.listen_module = Listen::Compat::Test::Simple

  fail 'No block given!' unless block_given?

  @thread = Thread.new { _supervise(&block) }
end

Instance Method Details

#instancesObject

Return a list of fake Listen instances actually created



34
35
36
# File 'lib/listen/compat/test/session.rb', line 34

def instances
  @instances ||= Fake.collect_instances(@thread)
end

#interruptObject

Simulate a Ctrl-C from the user



21
22
23
24
25
# File 'lib/listen/compat/test/session.rb', line 21

def interrupt
  _wait_until_ready
  @thread.raise Interrupt
  @thread.join
end

#simulate_events(modified, added, removed) ⇒ Object

Simulate Listen events you want passed asynchronously to your callback



28
29
30
31
# File 'lib/listen/compat/test/session.rb', line 28

def simulate_events(modified, added, removed)
  _wait_until_ready
  Fake.fire_events(@thread, *_events(modified, added, removed))
end