Module: AppMap::RSpec
- Defined in:
- lib/appmap/rspec.rb
Overview
Integration of AppMap with RSpec. When enabled with APPMAP=true, the AppMap tracer will
be activated around each scenario which has the metadata key :appmap.
Defined Under Namespace
Classes: Recording, ScopeExample, ScopeExampleGroup
Constant Summary collapse
- APPMAP_OUTPUT_DIR =
'tmp/appmap/rspec'- LOG =
false
Class Method Summary collapse
- .add_event_methods(event_methods) ⇒ Object
- .begin_spec(example) ⇒ Object
- .config ⇒ Object
- .enabled? ⇒ Boolean
- .end_spec(example, exception:) ⇒ Object
- .first_recording? ⇒ Boolean
- .init ⇒ Object
- .metadata ⇒ Object
- .run ⇒ Object
- .save(name:, class_map:, source_location:, test_status:, exception:, events:) ⇒ Object
Class Method Details
.add_event_methods(event_methods) ⇒ Object
180 181 182 |
# File 'lib/appmap/rspec.rb', line 180 def add_event_methods(event_methods) @event_methods += event_methods end |
.begin_spec(example) ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/appmap/rspec.rb', line 156 def begin_spec(example) AppMap.info 'Configuring AppMap recorder for RSpec' if first_recording? @recording_count += 1 recording = if example.[:appmap] != false Recording.new(example) else :false end @recordings_by_example[example.object_id] = recording end |
.config ⇒ Object
176 177 178 |
# File 'lib/appmap/rspec.rb', line 176 def config @config or raise "AppMap is not configured" end |
.enabled? ⇒ Boolean
218 219 220 |
# File 'lib/appmap/rspec.rb', line 218 def enabled? ENV['APPMAP'] == 'true' end |
.end_spec(example, exception:) ⇒ Object
169 170 171 172 173 174 |
# File 'lib/appmap/rspec.rb', line 169 def end_spec(example, exception:) recording = @recordings_by_example.delete(example.object_id) return warn "No recording found for #{example}" unless recording recording.finish exception unless recording == :false end |
.first_recording? ⇒ Boolean
152 153 154 |
# File 'lib/appmap/rspec.rb', line 152 def first_recording? @recording_count == 0 end |
.init ⇒ Object
148 149 150 |
# File 'lib/appmap/rspec.rb', line 148 def init FileUtils.mkdir_p APPMAP_OUTPUT_DIR end |
.metadata ⇒ Object
14 15 16 |
# File 'lib/appmap/rspec.rb', line 14 def self. AppMap. end |
.run ⇒ Object
222 223 224 |
# File 'lib/appmap/rspec.rb', line 222 def run init end |
.save(name:, class_map:, source_location:, test_status:, exception:, events:) ⇒ Object
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/appmap/rspec.rb', line 184 def save(name:, class_map:, source_location:, test_status:, exception:, events:) = AppMap::RSpec..tap do |m| m[:name] = name m[:source_location] = source_location m[:app] = AppMap.configuration.name m[:frameworks] ||= [] m[:frameworks] << { name: 'rspec', version: Gem.loaded_specs['rspec-core']&.version&.to_s } m[:recorder] = { name: 'rspec', type: 'tests' } m[:test_status] = test_status if exception m[:exception] = { class: exception.class.name, message: AppMap::Event::MethodEvent.display_string(exception.to_s) } end end appmap = { version: AppMap::APPMAP_FORMAT_VERSION, metadata: , classMap: class_map, events: events }.compact fname = AppMap::Util.scenario_filename(name) AppMap::Util.write_appmap(File.join(APPMAP_OUTPUT_DIR, fname), appmap) end |