Class: NeuronCheckSystem::MatcherBase

Inherits:
Object
  • Object
show all
Defined in:
lib/neuroncheck/matcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expected, declared_caller_locations) ⇒ MatcherBase

Returns a new instance of MatcherBase.



42
43
44
45
# File 'lib/neuroncheck/matcher.rb', line 42

def initialize(expected, declared_caller_locations)
  @expected = expected
  @declared_caller_locations = declared_caller_locations
end

Instance Attribute Details

#declared_caller_locationsObject

Returns the value of attribute declared_caller_locations.



40
41
42
# File 'lib/neuroncheck/matcher.rb', line 40

def declared_caller_locations
  @declared_caller_locations
end

Instance Method Details

#expected_captionObject

Raises:

  • (NotImplementedError)


76
77
78
# File 'lib/neuroncheck/matcher.rb', line 76

def expected_caption
  raise NotImplementedError
end

#expected_short_captionObject



80
81
82
# File 'lib/neuroncheck/matcher.rb', line 80

def expected_short_caption
  @expected.inspect
end

#get_error_message(signature_decl, context_caption, value, phrase_after_but: 'was') ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/neuroncheck/matcher.rb', line 51

def get_error_message(signature_decl, context_caption, value, phrase_after_but: 'was')
  locs = Utils.backtrace_locations_to_captions(@declared_caller_locations)

  ret = ""
  ret.concat("\#{context_caption} must be \#{expected_caption}, but \#{phrase_after_but} \#{Utils.truncate(value.inspect, 40)}\n      got: \#{value.inspect}\n")

  if signature_decl and signature_decl.assigned_method then
    ret.concat("signature: \#{signature_decl.signature_caption}\n")
  end

  if locs.size >= 1 then
    ret.concat("  declared at: \#{locs.join(\"\\n\" + ' ' * 15)}\n\n")
  end

  ret
end

#match?(value, self_object) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


47
48
49
# File 'lib/neuroncheck/matcher.rb', line 47

def match?(value, self_object)
  raise NotImplementedError
end

#meta_info_as_jsonObject



84
85
86
87
88
89
90
# File 'lib/neuroncheck/matcher.rb', line 84

def meta_info_as_json
  re = {}
  re['type'] = self.class.name.split('::')[-1]
  re['expected'] = @expected

  re
end