Class: LedgerSync::Ledgers::TestLedger::Util::ErrorMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/ledger_sync/test/support/test_ledger/util/error_matcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error:) ⇒ ErrorMatcher

Returns a new instance of ErrorMatcher.



11
12
13
14
# File 'lib/ledger_sync/test/support/test_ledger/util/error_matcher.rb', line 11

def initialize(error:)
  @error = error
  @message = error.message.to_s
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



8
9
10
# File 'lib/ledger_sync/test/support/test_ledger/util/error_matcher.rb', line 8

def error
  @error
end

#messageObject (readonly)

Returns the value of attribute message.



8
9
10
# File 'lib/ledger_sync/test/support/test_ledger/util/error_matcher.rb', line 8

def message
  @message
end

Instance Method Details

#bodyObject



16
17
18
19
20
# File 'lib/ledger_sync/test/support/test_ledger/util/error_matcher.rb', line 16

def body
  error.response.body
rescue NoMethodError
  nil
end

#codeObject

rubocop:disable Metrics/CyclomaticComplexity



41
42
43
44
# File 'lib/ledger_sync/test/support/test_ledger/util/error_matcher.rb', line 41

def code # rubocop:disable Metrics/CyclomaticComplexity
  ((body && JSON.parse(body).dig('fault', 'error')&.first&.fetch('code')) ||
  (body && JSON.parse(body).dig('Fault', 'Error')&.first&.fetch('code'))).to_i
end

#detailObject

rubocop:disable Metrics/CyclomaticComplexity



36
37
38
39
# File 'lib/ledger_sync/test/support/test_ledger/util/error_matcher.rb', line 36

def detail # rubocop:disable Metrics/CyclomaticComplexity
  (body && JSON.parse(body).dig('fault', 'error')&.first&.fetch('detail')) ||
    (body && JSON.parse(body).dig('Fault', 'Error')&.first&.fetch('Detail'))
end

#error_classObject

Raises:

  • (NotImplementedError)


22
23
24
# File 'lib/ledger_sync/test/support/test_ledger/util/error_matcher.rb', line 22

def error_class
  raise NotImplementedError
end

#error_messageObject

rubocop:disable Metrics/CyclomaticComplexity



26
27
28
29
30
31
32
33
34
# File 'lib/ledger_sync/test/support/test_ledger/util/error_matcher.rb', line 26

def error_message # rubocop:disable Metrics/CyclomaticComplexity
  return error.message unless body

  parsed_body = JSON.parse(body)

  parsed_body.dig('fault', 'error')&.first&.fetch('message') ||
    parsed_body.dig('Fault', 'Error')&.first&.fetch('Message') ||
    parsed_body['error']
end

#match?Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


46
47
48
# File 'lib/ledger_sync/test/support/test_ledger/util/error_matcher.rb', line 46

def match?
  raise NotImplementedError
end

#output_messageObject

Raises:

  • (NotImplementedError)


50
51
52
# File 'lib/ledger_sync/test/support/test_ledger/util/error_matcher.rb', line 50

def output_message
  raise NotImplementedError
end