Class: FilterTable::ExceptionCatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/utils/filter.rb

Instance Method Summary collapse

Constructor Details

#initialize(original_resource, original_exception) ⇒ ExceptionCatcher

Returns a new instance of ExceptionCatcher.



10
11
12
13
# File 'lib/utils/filter.rb', line 10

def initialize(original_resource, original_exception)
  @original_resource = original_resource
  @original_exception = original_exception
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missingObject

Capture message chains and return ‘ExceptionCatcher` objects



34
35
36
# File 'lib/utils/filter.rb', line 34

def method_missing(*)
  self
end

Instance Method Details

#resource_exception_messageObject



29
30
31
# File 'lib/utils/filter.rb', line 29

def resource_exception_message
  @original_exception.message
end

#resource_failed?Boolean

This method is called via the runner and signals RSpec to output a block showing why the resource failed. This prevents the resource from being added to the test collection and being evaluated.

Returns:

  • (Boolean)


25
26
27
# File 'lib/utils/filter.rb', line 25

def resource_failed?
  @original_exception.is_a?(Inspec::Exceptions::ResourceFailed)
end

#resource_skipped?Boolean

This method is called via the runner and signals RSpec to output a block showing why the resource was skipped. This prevents the resource from being added to the test collection and being evaluated.

Returns:

  • (Boolean)


18
19
20
# File 'lib/utils/filter.rb', line 18

def resource_skipped?
  @original_exception.is_a?(Inspec::Exceptions::ResourceSkipped)
end

#respond_to?(_method) ⇒ Boolean

RSpec will check the object returned to see if it responds to a method before calling it. We need to fake it out and tell it that it does. This allows it to skip past that check and fall through to #method_missing

Returns:

  • (Boolean)


41
42
43
# File 'lib/utils/filter.rb', line 41

def respond_to?(_method)
  true
end

#to_sObject Also known as: inspect



45
46
47
# File 'lib/utils/filter.rb', line 45

def to_s
  @original_resource.to_s
end