Class: Object

Inherits:
BasicObject
Defined in:
lib/web/assertinclude.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#__index(key) ⇒ Object



32
33
34
# File 'lib/web/assertinclude.rb', line 32

def __index(key)
  send key.intern
end

#do_thing(haystack, k, v, fullname, fullname_str) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/web/assertinclude.rb', line 36

def do_thing haystack, k, v, fullname, fullname_str
  message = ""
  # get key
  if !haystack.has_key?(k)
    if v
      message += "Missing from actual: #{fullname_str} => #{v.inspect}\n"
    end
  else
      # inspect key
    # if we are looking for a collection
    if v.kind_of?(Hash) || v.kind_of?(Array)
      # and the haystack has a collection
      if !(haystack.__index(k).kind_of?(String) || haystack.__index(k).kind_of?(TrueClass) || haystack.__index(k).kind_of?(FalseClass) || haystack.__index(k).kind_of?(Fixnum) || haystack.__index(k).kind_of?(Bignum))
        # recurse if both are collections
        message += v.compare_includes?(haystack.__index(k),fullname)
        
        # otherwise, complain that we aren't the same
      else
        message += "Difference: required <#{fullname_str} => #{v.inspect}> was <#{fullname_str} => #{haystack.__index(k).inspect}>\n" 
      end
      
      # if we aren't looking for a collection, see if we aren't the same
    else
      haystack_value = haystack.__index(k)
      if (haystack_value.kind_of? Array and
            haystack_value.length == 1)
        haystack_value = haystack_value.first
      end
      if (haystack_value != v)
        message += "Difference: required <#{fullname_str} => #{v.inspect}> was <#{fullname_str} => #{haystack_value.inspect}>\n" 
      end
    end
  end
  message
end

#has_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/web/assertinclude.rb', line 28

def has_key? key
  respond_to? key.intern
end