Module: AppMap::Rswag

Defined in:
lib/appmap/rswag.rb

Class Method Summary collapse

Class Method Details

.enabled?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/appmap/rswag.rb', line 45

def enabled?
  RSpec.enabled? && defined?(Rswag)
end

.record(metadata, &block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/appmap/rswag.rb', line 7

def self.record(, &block)
  description = [:full_description]
  warn "Recording of RSwag test #{description}" if AppMap::RSpec::LOG
  source_location = ([:example_group] || {})[:location]

  appmap = AppMap.record(&block)

  events = appmap['events']
  class_map = appmap['classMap']

  exception = (events.last || {})[:exception]
  failed = true if exception
  warn "Finishing recording of #{failed ? 'failed ' : ''} RSwag test #{description}" if AppMap::RSpec::LOG
  warn "Exception: #{exception}" if exception && AppMap::RSpec::LOG

  if failed
    warn "Failure exception: #{exception}" if AppMap::RSpec::LOG
    test_failure = Util.extract_test_failure(exception)
  end

  AppMap::RSpec.save name: description,
                     class_map: class_map,
                     source_location: source_location,
                     test_status: exception ? 'failed' : 'succeeded',
                     test_failure: test_failure,
                     exception: exception,
                     events: events,
                     frameworks: [
                       { name: 'rswag',
                         version: Gem.loaded_specs['rswag-specs']&.version&.to_s }
                     ],
                     recorder: {
                       name: 'rswag',
                       type: 'tests'
                     }
end