require 'pio/echo' describe Pio::Echo::Reply do describe '.new' do context 'with no arguments' do When(:echo_reply) { Pio::Echo::Reply.new } Then { echo_reply.ofp_version == 1 } Then { echo_reply.message_type == Pio::OpenFlow::Type::ECHO_REPLY } Then { echo_reply.message_length == 8 } Then { echo_reply.transaction_id == 0 } Then { echo_reply.xid == 0 } Then { echo_reply.user_data == '' } Then { echo_reply.to_binary == [1, 3, 0, 8, 0, 0, 0, 0].pack('C*') } end context 'with 123' do When(:echo_reply) { Pio::Echo::Reply.new(123) } Then { echo_reply.ofp_version == 1 } Then { echo_reply.message_type == Pio::OpenFlow::Type::ECHO_REPLY } Then { echo_reply.message_length == 8 } Then { echo_reply.transaction_id == 123 } Then { echo_reply.xid == 123 } Then { echo_reply.user_data == '' } Then { echo_reply.to_binary == [1, 3, 0, 8, 0, 0, 0, 123].pack('C*') } end context 'with 2**32' do When(:result) { Pio::Echo::Reply.new(2**32) } Then { result == Failure(ArgumentError) } end context 'with transaction_id: 123' do When(:echo_reply) { Pio::Echo::Reply.new(transaction_id: 123) } Then { echo_reply.ofp_version == 1 } Then { echo_reply.message_type == Pio::OpenFlow::Type::ECHO_REPLY } Then { echo_reply.message_length == 8 } Then { echo_reply.transaction_id == 123 } Then { echo_reply.xid == 123 } Then { echo_reply.user_data == '' } Then { echo_reply.to_binary == [1, 3, 0, 8, 0, 0, 0, 123].pack('C*') } end context 'with xid: 123' do When(:echo_reply) { Pio::Echo::Reply.new(xid: 123) } Then { echo_reply.ofp_version == 1 } Then { echo_reply.message_type == Pio::OpenFlow::Type::ECHO_REPLY } Then { echo_reply.message_length == 8 } Then { echo_reply.transaction_id == 123 } Then { echo_reply.xid == 123 } Then { echo_reply.user_data == '' } Then { echo_reply.to_binary == [1, 3, 0, 8, 0, 0, 0, 123].pack('C*') } end context "with transaction_id: 123, user_data: 'foobar'" do When(:echo_reply) { Pio::Echo::Reply.new(xid: 123, user_data: 'foobar') } Then { echo_reply.ofp_version == 1 } Then { echo_reply.message_type == Pio::OpenFlow::Type::ECHO_REPLY } Then { echo_reply.message_length == 14 } Then { echo_reply.transaction_id == 123 } Then { echo_reply.xid == 123 } Then { echo_reply.user_data == 'foobar' } Then do echo_reply.to_binary == [1, 3, 0, 14, 0, 0, 0, 123, 102, 111, 111, 98, 97, 114].pack('C*') end end context 'with :INVALID_ARGUMENT' do When(:result) { Pio::Echo::Reply.new(:INVALID_ARGUMENT) } Then { result == Failure(TypeError) } end end end