Class: LanGrove::SpecHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/langrove/ext/spec_helper.rb

Class Method Summary collapse

Class Method Details

.create_daemon_with_connected_handler(daemon_name, anything, handler_count = 1) ⇒ Object

# # To get a ‘daemon’ up in the specs. #

DAEMON_ROOT = File.expand_path(‘../../’, __FILE__) CONFIG = LanGrove::FakeConfig.new LOG = LanGrove::FakeLogger ROOT = LanGrove::Root::Base.new( CONFIG, LOG )

@daemon, @server, @adaptor, @handlers, @protocols =

LanGrove::SpecHelper.create_daemon_with_connected_handler( subject )


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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/langrove/ext/spec_helper.rb', line 24

def create_daemon_with_connected_handler( daemon_name, anything, handler_count = 1 )

  #
  # Spawn a 'fake' running daemon and return
  # 
  # <the running daemon>, 
  # <the server module>, 
  # <the adaptor>, 
  # <<count> connected_handler>, 
  # <<count> connected_handler protocol instance>
  #

  #
  # Reload the config, 
  # 
  # ...spec may have set up some test config
  #

  daemon = LanGrove::Daemon::Base.new( ROOT, CONFIG.hash, daemon_name )

  server = daemon.instance_variable_get( :@server )

  adaptor = daemon.instance_variable_get( :@adaptor )

  handlers = []
  protocols = []

  yielder = adaptor.should_receive( :connector ).with( anything )

  0.upto( handler_count - 1 ) do |count|

    handlers << daemon.instance_variable_get( :@handler ).new( {} )

    yielder.and_yield( handlers[count] )

  end

  daemon.run

  0.upto( handler_count - 1 ) do |count|

    protocols << handlers[0].instance_variable_get( :@protocol )

  end

  
  if handler_count == 1 

    return daemon, server, adaptor, handlers[0], protocols[0]

  end

  return daemon, server, adaptor, handlers, protocols

end