Class: Object

Inherits:
BasicObject
Defined in:
lib/web/assertinclude.rb,
lib/web/resources/test/counter.rb

Overview

:nodoc:

Constant Summary collapse

@@rbw_count =
nil

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.rbw_countObject



4
5
6
# File 'lib/web/resources/test/counter.rb', line 4

def Object::rbw_count
  @@rbw_count
end

.rbw_count=(other) ⇒ Object



7
8
9
# File 'lib/web/resources/test/counter.rb', line 7

def Object::rbw_count= other
  @@rbw_count = other
end

Instance Method Details

#__index(key) ⇒ Object



41
42
43
# File 'lib/web/assertinclude.rb', line 41

def __index(key)
  send key.intern
end

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



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
71
72
73
74
75
76
77
78
79
# File 'lib/web/assertinclude.rb', line 45

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)


37
38
39
# File 'lib/web/assertinclude.rb', line 37

def has_key? key
  respond_to? key.intern
end