Class: Rspec::Bash::StubServer
- Inherits:
-
Object
- Object
- Rspec::Bash::StubServer
- Defined in:
- lib/rspec/bash/server/stub_server.rb
Instance Method Summary collapse
- #accept_loop(tcp_server, loop_forever = true) ⇒ Object
-
#initialize(call_log_manager, call_conf_manager, stub_marshaller) ⇒ StubServer
constructor
A new instance of StubServer.
- #process(client_message) ⇒ Object
- #process_stub_call(stub_call) ⇒ Object
- #start(tcp_server) ⇒ Object
Constructor Details
#initialize(call_log_manager, call_conf_manager, stub_marshaller) ⇒ StubServer
Returns a new instance of StubServer.
6 7 8 9 10 |
# File 'lib/rspec/bash/server/stub_server.rb', line 6 def initialize(call_log_manager, call_conf_manager, stub_marshaller) @call_log_manager = call_log_manager @call_conf_manager = call_conf_manager @stub_marshaller = stub_marshaller end |
Instance Method Details
#accept_loop(tcp_server, loop_forever = true) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/rspec/bash/server/stub_server.rb', line 18 def accept_loop(tcp_server, loop_forever = true) loop do tcp_socket = tcp_server.accept = process(tcp_socket.read) tcp_socket.write() tcp_socket.close break unless loop_forever end end |
#process(client_message) ⇒ Object
28 29 30 31 32 |
# File 'lib/rspec/bash/server/stub_server.rb', line 28 def process() client_call = @stub_marshaller.unmarshal() server_conf = process_stub_call(client_call) @stub_marshaller.marshal(server_conf) end |
#process_stub_call(stub_call) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rspec/bash/server/stub_server.rb', line 34 def process_stub_call(stub_call) @call_log_manager.add_log( stub_call[:command], stub_call[:stdin], stub_call[:args] ) @call_conf_manager.get_best_call_conf( stub_call[:command], stub_call[:args] ) end |
#start(tcp_server) ⇒ Object
12 13 14 15 16 |
# File 'lib/rspec/bash/server/stub_server.rb', line 12 def start(tcp_server) Thread.new do accept_loop(tcp_server) end end |