Method: EtherShell::ShellDsl#expect
- Defined in:
- lib/ether_shell/shell_dsl.rb
#expect(packet_data) ⇒ Object
Receives a packet and matches it against an expected value.
Args:
packet_data:: an Array of integers (bytes), a hex string starting with 0x,
or a string of raw bytes
Raises:
RuntimeError:: if the shell was not connected to a socket by a call to
connect or socket
RuntimeError:: if the received packet doesn't match the expected value
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/ether_shell/shell_dsl.rb', line 97 def expect(packet_data) raise "Not connected. did you forget to call connect?" unless @_socket expected_bytes = EtherShell::ShellDsl.parse_packet_data packet_data print "Receiving... " if @_verbose bytes = @_socket.recv print " #{bytes.unpack('H*').first} " if @_verbose if bytes == expected_bytes print "OK\n" if @_verbose else print "!= #{expected_bytes.unpack('H*').first} ERROR\n" if @_verbose raise EtherShell::ExpectationError, "#{bytes.unpack('H*').first} != #{expected_bytes.unpack('H*').first}" end EtherShell::ShellDsl.nothing end |