Class: AppMap::RSpec::Recording
- Inherits:
-
Struct
- Object
- Struct
- AppMap::RSpec::Recording
- Defined in:
- lib/appmap/rspec.rb
Instance Attribute Summary collapse
-
#example ⇒ Object
Returns the value of attribute example.
Instance Method Summary collapse
- #finish ⇒ Object
-
#initialize(example) ⇒ Recording
constructor
A new instance of Recording.
Constructor Details
#initialize(example) ⇒ Recording
Returns a new instance of Recording.
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/appmap/rspec.rb', line 124 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.[:http_client].instance_variable_get('@server_url').port end warn "Starting recording of example #{example}" if AppMap::RSpec::LOG @trace = AppMap.tracing.trace @webdriver_port = webdriver_port.() end |
Instance Attribute Details
#example ⇒ Object
Returns the value of attribute example
123 124 125 |
# File 'lib/appmap/rspec.rb', line 123 def example @example end |
Instance Method Details
#finish ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/appmap/rspec.rb', line 141 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: false) description = [] scope = ScopeExample.new(example) feature_group = feature = nil labels = [] while scope labels += scope.labels description << scope.description feature ||= scope.feature feature_group ||= scope.feature_group scope = scope.parent end labels = labels.map(&:to_s).map(&:strip).reject(&:blank?).map(&:downcase).uniq 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(' ')) compute_feature_name = lambda do return 'unknown' if description.empty? feature_description = description.dup num_tokens = [2, feature_description.length - 1].min feature_description[0...num_tokens].map(&:strip).join(' ') end feature_group ||= normalize.call(default_description).underscore.gsub('/', '_').humanize feature_name = feature || compute_feature_name.call if feature_group feature_name = normalize.call(feature_name) if feature_name AppMap::RSpec.save full_description, class_map, events: events, feature_name: feature_name, feature_group_name: feature_group, labels: labels.blank? ? nil : labels end |