Class: Capybara::Storyboard::Session
- Inherits:
-
Object
- Object
- Capybara::Storyboard::Session
- Defined in:
- lib/capybara/storyboard/session.rb
Overview
Per-example state (sequence counter, output directory, enabled flag, example metadata) plus filename / path / sanitize derivation.
Extracting this state out of TestHelper keeps its unit tests independent
of Capybara and RSpec hooks: a Session can be built with a plain example
double and an injected output_root.
Instance Method Summary collapse
-
#auto(page, action, detail = nil) ⇒ Object
Automatic screenshot for a DSL action.
- #enabled? ⇒ Boolean
-
#initialize(example:, enabled:, output_root: nil) ⇒ Session
constructor
A new instance of Session.
-
#manual(page, label) ⇒ Object
Manual screenshot hook.
-
#suppress_captures ⇒ Object
Suppresses automatic/manual captures for the duration of the block.
- #suppressed? ⇒ Boolean
Constructor Details
#initialize(example:, enabled:, output_root: nil) ⇒ Session
Returns a new instance of Session.
15 16 17 18 19 20 21 22 |
# File 'lib/capybara/storyboard/session.rb', line 15 def initialize(example:, enabled:, output_root: nil) @example = example @enabled = enabled @output_root = output_root @index = 0 @dir = nil @suppression_depth = 0 end |
Instance Method Details
#auto(page, action, detail = nil) ⇒ Object
Automatic screenshot for a DSL action. No-op unless enabled.
29 30 31 32 33 34 35 |
# File 'lib/capybara/storyboard/session.rb', line 29 def auto(page, action, detail = nil) return unless @enabled return if suppressed? label = [action, sanitize(detail)].compact_blank.join('_') capture_with_label(page, label) end |
#enabled? ⇒ Boolean
24 25 26 |
# File 'lib/capybara/storyboard/session.rb', line 24 def enabled? @enabled end |
#manual(page, label) ⇒ Object
Manual screenshot hook. Like #auto, captured only when enabled. For an unconditional screenshot, use Capybara's own save_screenshot. The page is passed explicitly rather than held as state.
40 41 42 43 44 45 |
# File 'lib/capybara/storyboard/session.rb', line 40 def manual(page, label) return unless @enabled return if suppressed? capture_with_label(page, sanitize(label)) end |
#suppress_captures ⇒ Object
Suppresses automatic/manual captures for the duration of the block. Used to skip nested captures while a confirm/alert dialog is open, where a screenshot or JS eval would raise UnexpectedAlertOpenError. A depth counter (not a boolean) supports nesting; the ensure guarantees reset on exceptions.
51 52 53 54 55 56 |
# File 'lib/capybara/storyboard/session.rb', line 51 def suppress_captures @suppression_depth += 1 yield ensure @suppression_depth -= 1 end |
#suppressed? ⇒ Boolean
58 59 60 |
# File 'lib/capybara/storyboard/session.rb', line 58 def suppressed? @suppression_depth.positive? end |