Class: AppMap::RSpec::Recording

Inherits:
Struct
  • Object
show all
Defined in:
lib/appmap/rspec.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(example) ⇒ Recording

Returns a new instance of Recording.



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/appmap/rspec.rb', line 76

def initialize(example)
  super

  webdriver_port = lambda do
    next unless defined?(page) && page&.driver

    # This is the ugliest thing ever but I don't want to lose it.
    # All the WebDriver calls are getting app-mapped and it's really unclear
    # what they are.
    page.driver.options[:http_client].instance_variable_get('@server_url').port
  end

  warn "Starting recording of example #{example}@#{source_location}" if AppMap::RSpec::LOG
  @trace = AppMap.tracing.trace
  @webdriver_port = webdriver_port.()
end

Instance Attribute Details

#exampleObject

Returns the value of attribute example

Returns:

  • (Object)

    the current value of example



75
76
77
# File 'lib/appmap/rspec.rb', line 75

def example
  @example
end

Instance Method Details

#finish(exception) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/appmap/rspec.rb', line 99

def finish(exception)
  warn "Finishing recording of example #{example}" if AppMap::RSpec::LOG
  warn "Exception: #{exception}" if exception && AppMap::RSpec::LOG

  events = []
  AppMap.tracing.delete @trace

  events << @trace.next_event.to_h while @trace.event?

  AppMap::RSpec.add_event_methods @trace.event_methods

  class_map = AppMap.class_map(@trace.event_methods)

  description = []
  scope = ScopeExample.new(example)
  while scope
    description << scope.description
    scope = scope.parent
  end

  description.reject!(&:nil?)
  description.reject!(&Util.method(:blank?))
  default_description = description.last
  description.reverse!

  normalize = lambda do |desc|
    desc.gsub('it should behave like', '')
        .gsub(/Controller$/, '')
        .gsub(/\s+/, ' ')
        .strip
  end

  full_description = normalize.call(description.join(' '))

  AppMap::RSpec.save name: full_description,
                     class_map: class_map,
                     source_location: source_location,
                     test_status: exception ? 'failed' : 'succeeded',
                     exception: exception,
                     events: events
end

#source_locationObject



93
94
95
96
97
# File 'lib/appmap/rspec.rb', line 93

def source_location
  result = example.location_rerun_argument.split(':')[0]
  result = result[2..-1] if result.index('./') == 0
  result
end