module Cucumber module WireSupport # Represents the packet of data sent over the wire as JSON data, containing # a message and a hash of arguments class WirePacket class << self def parse(raw) attributes = JSON.parse(raw.strip) message = attributes[0] params = attributes[1] new(message, params) end end attr_reader :message, :params def initialize(message, params) @message, @params = message, params end def to_json [@message, @params].to_json end def raise_if_bad raise WireException.new(@params) if @message == 'fail' || @message == 'step_failed' end def handle_with(handler) handler.send("handle_#{@message}", @params) end end end end