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



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

def initialize(example)
  super

  webdriver_port = lambda do
    return 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



72
73
74
# File 'lib/appmap/rspec.rb', line 72

def example
  @example
end

Instance Method Details

#finishObject



96
97
98
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
# File 'lib/appmap/rspec.rb', line 96

def finish
  warn "Finishing recording of example #{example}" if 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, include_source: AppMap.include_source?)

  description = []
  scope = ScopeExample.new(example)

  while scope
    description << scope.description
    scope = scope.parent
  end

  description.reject!(&:nil?).reject!(&: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 full_description,
                     class_map,
                     source_location,
                     events: events
end

#source_locationObject



90
91
92
93
94
# File 'lib/appmap/rspec.rb', line 90

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