Ravn::SpecHelpers::NetHelpers::

BeMessagepackedMatcher class

Expectations

Public Class Methods

new( expected_type )
# File lib/ravn/spec_helpers/net_helpers.rb, line 21
def initialize( expected_type )
        @expected_type = expected_type
        @actual_value = nil
        @decoded = nil
        @exception = nil
end

Public Instance Methods

failure_message()
# File lib/ravn/spec_helpers/net_helpers.rb, line 53
def failure_message
        "expected %p to be a msgpacked %p but %s" % [ @actual_value, @expected_type, self.failure_reason ]
end
failure_message_when_negated()
# File lib/ravn/spec_helpers/net_helpers.rb, line 58
def failure_message_when_negated
        "expected %p not to be a msgpacked %p, but it was" % [ @actual_value, @actual_value ]
end
failure_reason()
# File lib/ravn/spec_helpers/net_helpers.rb, line 39
def failure_reason
        if @exception && @exception.is_a?( MessagePack::MalformedFormatError )
                return "it was not formatted correctly: %s" % [ @exception.message ]
        elsif @exception
                return "there was a %p when trying to decode it: %s" %
                        [ @exception.class, @exception.message ]
        elsif @decoded && !@decoded.is_a?( @expected_type )
                return "it was a msgpacked %p" % [ @decoded.class ]
        else
                return 'there was an unknown problem'
        end
end
matches?( actual_value )
# File lib/ravn/spec_helpers/net_helpers.rb, line 29
def matches?( actual_value )
        @actual_value = actual_value
        @decoded = MessagePack.unpack( actual_value )
        return @decoded.is_a?( @expected_type )
rescue => err
        @exception = err
        return false
end