Module: CapProxy::TestWrapper

Defined in:
lib/cap_proxy/testkit/em_wrapper.rb

Defined Under Namespace

Classes: SimpleResponder

Class Method Summary collapse

Class Method Details

.run(example, bind_address, target) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/cap_proxy/testkit/em_wrapper.rb', line 15

def self.run(example, bind_address, target)
  em_init = Queue.new
  example_finished = EM::Queue.new

  Thread.new do
    EM.run do
      EM.error_handler do |error|
        STDERR.puts error
        STDERR.puts error.backtrace.map {|l| "\t#{l}" }
      end

      logger = Logger.new(STDERR)
      logger.level = Logger::ERROR
      proxy = Server.new(bind_address, target, logger)
      proxy.run!

      example_finished.pop do |q|
        EM.stop_event_loop
        q.push(nil)
      end

      em_init.push(proxy)
    end
  end

  proxy = em_init.pop
  if block_given?
    yield proxy
  end

  example.run

  q = Queue.new
  example_finished.push(q)
  q.pop
end