Module: Capybara::Maleficent
- Defined in:
- lib/capybara/maleficent.rb,
lib/capybara/maleficent/logger.rb,
lib/capybara/maleficent/version.rb,
lib/capybara/maleficent/configuration.rb
Defined Under Namespace
Modules: Spindle
Classes: Configuration, Logger
Constant Summary
collapse
- VERSION =
"0.3.0"
Class Method Summary
collapse
Class Method Details
.configuration ⇒ Object
49
50
51
|
# File 'lib/capybara/maleficent.rb', line 49
def self.configuration
@configuration || Configuration.new
end
|
53
54
55
56
57
|
# File 'lib/capybara/maleficent.rb', line 53
def self.configure
@configuration = Configuration.new
yield(@configuration)
@configuration
end
|
.default_sleeper ⇒ Object
45
46
47
|
# File 'lib/capybara/maleficent.rb', line 45
def self.default_sleeper
Kernel
end
|
.with_sleep_injection(the_sleeper: Kernel, logger: configuration.logger, sleep_durations: configuration.sleep_durations, handled_exceptions: configuration.handled_exceptions) { ... } ⇒ Object
A method that wraps the given block in a retry sleep strategy. Of particular use for waiting on Capybara.
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/capybara/maleficent.rb', line 17
def self.with_sleep_injection(the_sleeper: Kernel, logger: configuration.logger, sleep_durations: configuration.sleep_durations, handled_exceptions: configuration.handled_exceptions)
logger.debug "Starting Capybara::Maleficent.with_sleep_injection"
sleep_durations = sleep_durations.clone
last_try_sleep_duration = sleep_durations.pop
return_value = nil
success = false
sleep_durations.each do |sleep_duration|
begin
return_value = yield.tap { success = true }
break if success
rescue *handled_exceptions
logger.info "Sleeping for #{sleep_duration} via Capybara::Maleficent.with_sleep_injection (for #{handled_exceptions.inspect})"
the_sleeper.sleep(sleep_duration)
next
end
end
if success
logger.debug "Ending Capybara::Maleficent.with_sleep_injection"
return return_value
else
logger.info "Sleeping for #{last_try_sleep_duration}via Capybara::Maleficent.with_sleep_injection (for #{handled_exceptions.inspect}). This is the last try."
the_sleeper.sleep(last_try_sleep_duration)
yield.tap do
logger.debug "Ending Capybara::Maleficent.with_sleep_injection"
end
end
end
|