Class: Roby::Queries::CodeErrorMatcher

Inherits:
LocalizedErrorMatcher show all
Defined in:
lib/roby/queries/code_error_matcher.rb

Overview

Matcher for CodeError exceptions

In addition to the LocalizedError properties, it allows to match properties on the Ruby exception that has been thrown

Instance Attribute Summary collapse

Attributes inherited from LocalizedErrorMatcher

#failure_point_matcher, #model, #original_exception_model

Attributes inherited from MatcherBase

#neg_predicates, #predicates

Instance Method Summary collapse

Methods inherited from LocalizedErrorMatcher

#emitted, #matches_task?, #to_execution_exception_matcher, #with_model, #with_origin, #with_original_exception

Methods included from DRoby::V5::Queries::LocalizedErrorMatcherDumper

#droby_dump

Methods inherited from MatcherBase

#&, #add_neg_predicate, #add_predicate, declare_class_methods, #each, #each_in_plan, #indexed_query?, #match, match_predicate, match_predicates, #negate, #reset, #to_a, #to_set, #|

Constructor Details

#initializeCodeErrorMatcher

Returns a new instance of CodeErrorMatcher.



12
13
14
15
16
# File 'lib/roby/queries/code_error_matcher.rb', line 12

def initialize
    super
    @ruby_exception_class = Any
    with_model(CodeError)
end

Instance Attribute Details

#ruby_exception_classObject (readonly)

Returns the value of attribute ruby_exception_class.



10
11
12
# File 'lib/roby/queries/code_error_matcher.rb', line 10

def ruby_exception_class
  @ruby_exception_class
end

Instance Method Details

#===(error) ⇒ Object



33
34
35
36
37
# File 'lib/roby/queries/code_error_matcher.rb', line 33

def ===(error)
    return false unless super

    ruby_exception_class === error.error
end

#describe_failed_match(exception) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/roby/queries/code_error_matcher.rb', line 48

def describe_failed_match(exception)
    if (description = super)
        description
    elsif !(ruby_exception_class === exception.error)
        if ruby_exception_class
            "the underlying exception #{exception.error} does not "\
            "match the expected #{ruby_exception_class}"
        else
            "there is an underlying exception (#{exception.error}) "\
            "but the matcher expected none"
        end
    end
end

#to_sObject



39
40
41
42
43
44
45
46
# File 'lib/roby/queries/code_error_matcher.rb', line 39

def to_s
    description = super
    if ruby_exception_class
        "#{description}.with_ruby_exception(#{ruby_exception_class})"
    else
        "#{description}.without_ruby_exception"
    end
end

#with_ruby_exception(matcher) ⇒ Object

Match the underlying ruby exception

Parameters:

  • matcher (#===, Class)

    an object that can match an Exception object, usually an exception class



22
23
24
25
26
# File 'lib/roby/queries/code_error_matcher.rb', line 22

def with_ruby_exception(matcher)
    with_original_exception(matcher)
    @ruby_exception_class = matcher
    self
end

#without_ruby_exceptionObject

Match a CodeError without an original exception



29
30
31
# File 'lib/roby/queries/code_error_matcher.rb', line 29

def without_ruby_exception
    with_ruby_exception(nil)
end