Class: UnifiedMatchers::MatcherResult

Inherits:
Object
  • Object
show all
Defined in:
lib/unified_matchers/matcher_result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, ref, my, message_ref, message_my, default_message, status, data = nil, message = nil) ⇒ MatcherResult

Returns a new instance of MatcherResult.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/unified_matchers/matcher_result.rb', line 12

def initialize name, ref, my, message_ref, message_my, default_message, status, data=nil, message=nil
  if status == true or status == false
    @name = name
    @status = status
    @data = data
    @ref = ref
    @my = my
    @message_ref = message_ref
    @message_my = message_my
    if message.nil?
      message = default_message
    end
    @message_template = message
  else
    raise ArgumentError,
      "The status must be true or false, not #{status}."
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*a, &b) ⇒ Object



65
66
67
# File 'lib/unified_matchers/matcher_result.rb', line 65

def method_missing *a, &b
  @data.send(*a, &b)
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



10
11
12
# File 'lib/unified_matchers/matcher_result.rb', line 10

def data
  @data
end

#myObject (readonly)

Returns the value of attribute my.



10
11
12
# File 'lib/unified_matchers/matcher_result.rb', line 10

def my
  @my
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/unified_matchers/matcher_result.rb', line 10

def name
  @name
end

#refObject (readonly)

Returns the value of attribute ref.



10
11
12
# File 'lib/unified_matchers/matcher_result.rb', line 10

def ref
  @ref
end

Instance Method Details

#compute_messages(message) ⇒ Object



52
53
54
55
# File 'lib/unified_matchers/matcher_result.rb', line 52

def compute_messages message
  x = message.shift.inspect_for_unified_matchers
  message.inject(x) { |accu, y| y.gsub('%x', accu) }
end

#failure?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/unified_matchers/matcher_result.rb', line 35

def failure?
  ! @status
end

#messageObject



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/unified_matchers/matcher_result.rb', line 39

def message
  if defined? @message
    @message
  else
    str = ''
    str << 'not ' if failure?
    str << @message_template
    str.gsub!('%ref', compute_messages(@message_ref))
    str.gsub!('%my',  compute_messages(@message_my))
    @message = str
  end
end

#success?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/unified_matchers/matcher_result.rb', line 31

def success?
  @status
end

#to_sObject



57
58
59
60
61
62
63
# File 'lib/unified_matchers/matcher_result.rb', line 57

def to_s
  if @name.nil?
    message
  else
    "#@name: #{message}"
  end
end