Module: SnapshotInspector::Test::RSpecHelpers
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/snapshot_inspector/test/rspec_helpers.rb
Instance Method Summary collapse
-
#take_snapshot(snapshotee) ⇒ Object
Takes a snapshot of a given
snapshotee
.
Instance Method Details
#take_snapshot(snapshotee) ⇒ Object
Takes a snapshot of a given snapshotee
.
A snapshotee
can be an instance of ActionDispatch::TestResponse
or ActionMailer::MessageDelivery
.
take_snapshot
needs to be called after the snapshotee
object becomes available for inspection in the lifecycle of the spec (e.g. request or mailer spec). You can take one or more snapshots in a single spec.
Snapshots are taken only when explicitly enabled with an environment variable TAKE_SNAPSHOTS=1.
E.g. bin/rspec TAKE_SNAPSHOTS=1
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/snapshot_inspector/test/rspec_helpers.rb', line 20 def take_snapshot(snapshotee) return unless SnapshotInspector.configuration.snapshot_taking_enabled increment_take_snapshot_counter_scoped_by_test SnapshotInspector::Snapshot.persist( snapshotee: snapshotee, context: { test_framework: :rspec, example: RSpec.current_example..except(:execution_result).as_json.with_indifferent_access, take_snapshot_index: _take_snapshot_counter - 1 } ) end |