Module: AppMap::RSpec
- Defined in:
- lib/appmap/rspec.rb
Defined Under Namespace
Classes: Recording, ScopeExample, ScopeExampleGroup
Constant Summary collapse
- APPMAP_OUTPUT_DIR =
File.join(AppMap.output_dir, "rspec")
- LOG =
(ENV["APPMAP_DEBUG"] == "true" || ENV["DEBUG"] == "true")
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:, test_failure:, exception:, events:, frameworks: [], recorder: nil) ⇒ Object
Class Method Details
.add_event_methods(event_methods) ⇒ Object
191 192 193 |
# File 'lib/appmap/rspec.rb', line 191 def add_event_methods(event_methods) @event_methods += event_methods end |
.begin_spec(example) ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/appmap/rspec.rb', line 164 def begin_spec(example) AppMap::DetectEnabled.discourage_conflicting_recording_methods :rspec if first_recording? @recording_count += 1 # Disable RSpec recording for RSwag, because all the action happens in the before block. # The example is empty except for assertions. So RSwag has its own recorder, and RSpec # recording is disabled so it won't clobber the AppMap with empty data. recording = if example.[:appmap] == false || example.[:rswag] :disabled else Recording.new(example) end @recordings_by_example[example] = recording end |
.config ⇒ Object
187 188 189 |
# File 'lib/appmap/rspec.rb', line 187 def config @config or raise "AppMap is not configured" end |
.enabled? ⇒ Boolean
233 234 235 |
# File 'lib/appmap/rspec.rb', line 233 def enabled? AppMap.recording_enabled?(:rspec) end |
.end_spec(example, exception:) ⇒ Object
180 181 182 183 184 185 |
# File 'lib/appmap/rspec.rb', line 180 def end_spec(example, exception:) recording = @recordings_by_example.delete(example) return warn "No recording found for #{example}" unless recording recording.finish example.execution_result.exception || exception, exception unless recording == :disabled end |
.first_recording? ⇒ Boolean
160 161 162 |
# File 'lib/appmap/rspec.rb', line 160 def first_recording? @recording_count == 0 end |
.init ⇒ Object
156 157 158 |
# File 'lib/appmap/rspec.rb', line 156 def init FileUtils.mkdir_p APPMAP_OUTPUT_DIR end |
.run ⇒ Object
237 238 239 |
# File 'lib/appmap/rspec.rb', line 237 def run init end |
.save(name:, class_map:, source_location:, test_status:, test_failure:, exception:, events:, frameworks: [], recorder: nil) ⇒ Object
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/appmap/rspec.rb', line 195 def save(name:, class_map:, source_location:, test_status:, test_failure:, exception:, events:, frameworks: [], recorder: nil) = 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[:frameworks] += frameworks m[:recorder] = recorder || { name: "rspec", type: "tests" } m[:test_status] = test_status m[:test_failure] = test_failure if test_failure if exception m[:exception] = Util.format_exception(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 |