Module: Capybara::Lockstep::Configuration

Included in:
Capybara::Lockstep
Defined in:
lib/capybara-lockstep/configuration.rb

Instance Method Summary collapse

Instance Method Details

#after_synchronize(&callback) ⇒ Object



92
93
94
# File 'lib/capybara-lockstep/configuration.rb', line 92

def after_synchronize(&callback)
  after_synchronize_callbacks << callback
end

#debugObject



21
22
23
# File 'lib/capybara-lockstep/configuration.rb', line 21

def debug
  @debug.nil? ? false : @debug
end

#debug=(value) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/capybara-lockstep/configuration.rb', line 30

def debug=(value)
  @debug = value
  if value
    target_prose = (is_logger?(value) ? 'Ruby logger' : 'STDOUT')
    log "Logging to #{target_prose} and browser console"
  end

  send_config_to_browser(<<~JS)
    CapybaraLockstep.debug = #{debug?.to_json}
  JS

  @debug
end

#debug?Boolean

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/capybara-lockstep/configuration.rb', line 25

def debug?
  # @debug may also be a Logger object, so convert it to a boolean
  !!debug
end

#enabled=(enabled) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/capybara-lockstep/configuration.rb', line 64

def enabled=(enabled)
  case enabled
  when true
    log "Setting `Capybara::Lockstep.enabled = true` is deprecated. Set `Capybara::Lockstep.mode = :auto` instead."
    self.mode = :auto
  when false
    log "Setting `Capybara::Lockstep.enabled = false` is deprecated. Set `Capybara::Lockstep.mode = :manual` or `Capybara::Lockstep.mode = :off` instead."
    self.mode = :manual
  when nil
    # Reset to default
    self.mode = nil
  end
end

#modeObject



44
45
46
47
48
49
50
# File 'lib/capybara-lockstep/configuration.rb', line 44

def mode
  if javascript_driver?
    @mode.nil? ? :auto : @mode
  else
    :off
  end
end

#mode=(mode) ⇒ Object



52
53
54
# File 'lib/capybara-lockstep/configuration.rb', line 52

def mode=(mode)
  @mode = mode&.to_sym
end

#timeoutObject



5
6
7
# File 'lib/capybara-lockstep/configuration.rb', line 5

def timeout
  @timeout.nil? ? Capybara.default_max_wait_time : @timeout
end

#timeout=(seconds) ⇒ Object



9
10
11
# File 'lib/capybara-lockstep/configuration.rb', line 9

def timeout=(seconds)
  @timeout = seconds
end

#timeout_withObject



13
14
15
# File 'lib/capybara-lockstep/configuration.rb', line 13

def timeout_with
  @timeout_with.nil? ? :log : @timeout_with
end

#timeout_with=(action) ⇒ Object



17
18
19
# File 'lib/capybara-lockstep/configuration.rb', line 17

def timeout_with=(action)
  @timeout_with = action&.to_sym
end

#wait_tasksObject



78
79
80
# File 'lib/capybara-lockstep/configuration.rb', line 78

def wait_tasks
  @wait_tasks
end

#wait_tasks=(value) ⇒ Object



82
83
84
85
86
87
88
89
90
# File 'lib/capybara-lockstep/configuration.rb', line 82

def wait_tasks=(value)
  @wait_tasks = value

  send_config_to_browser(<<~JS)
    CapybaraLockstep.waitTasks = #{value.to_json}
  JS

  @wait_tasks
end

#with_mode(temporary_mode, &block) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/capybara-lockstep/configuration.rb', line 56

def with_mode(temporary_mode, &block)
  old_mode = mode
  self.mode = temporary_mode
  block.call
ensure
  self.mode = old_mode
end