Module: RSpec::Rewind
- Defined in:
- lib/rspec/rewind/api.rb,
lib/rspec/rewind/core.rb,
lib/rspec/rewind/event.rb,
lib/rspec/rewind/runner.rb,
lib/rspec/rewind/backoff.rb,
lib/rspec/rewind/version.rb,
lib/rspec/rewind/retry_gate.rb,
lib/rspec/rewind/retry_loop.rb,
lib/rspec/rewind/retry_budget.rb,
lib/rspec/rewind/retry_policy.rb,
lib/rspec/rewind/configuration.rb,
lib/rspec/rewind/retry_summary.rb,
lib/rspec/rewind/rspec_adapter.rb,
lib/rspec/rewind/runner_logger.rb,
lib/rspec/rewind/attempt_runner.rb,
lib/rspec/rewind/flaky_reporter.rb,
lib/rspec/rewind/retry_decision.rb,
lib/rspec/rewind/retry_notifier.rb,
lib/rspec/rewind/example_context.rb,
lib/rspec/rewind/example_methods.rb,
lib/rspec/rewind/flaky_transition.rb,
lib/rspec/rewind/retry_transition.rb,
lib/rspec/rewind/runner_components.rb,
lib/rspec/rewind/matcher_validation.rb,
lib/rspec/rewind/failure_fingerprint.rb,
lib/rspec/rewind/retry_event_builder.rb,
lib/rspec/rewind/retry_count_resolver.rb,
lib/rspec/rewind/retry_delay_resolver.rb,
lib/rspec/rewind/example_state_resetter.rb,
lib/rspec/rewind/configuration_validation.rb,
lib/rspec/rewind/runner_component_factory.rb
Defined Under Namespace
Modules: Backoff, ConfigurationValidation, ExampleMethods, FailureFingerprint, MatcherValidation
Classes: AttemptRunner, BudgetDecision, Configuration, Event, ExampleContext, ExampleStateResetter, FileRetryBudget, FlakyReporter, FlakyThresholdExceeded, FlakyTransition, RSpecAdapter, RetryBudget, RetryContext, RetryCountResolver, RetryDecision, RetryDecisionResult, RetryDelayResolver, RetryEventBuilder, RetryGate, RetryGateDecision, RetryLoop, RetryNotifier, RetryPolicy, RetrySummary, RetryTransition, Runner, RunnerComponentFactory, RunnerComponents, RunnerLogger, SleepMeasurement
Constant Summary
collapse
- PUBLIC_API =
[
Backoff,
Configuration,
Event,
FileRetryBudget,
FlakyReporter,
RetryBudget,
RetryDecision,
RetryPolicy,
Runner
].freeze
- INTERNAL_API =
[
AttemptRunner,
ExampleContext,
ExampleMethods,
ExampleStateResetter,
FailureFingerprint,
FlakyTransition,
RetryCountResolver,
RetryDelayResolver,
RetryEventBuilder,
RetryGate,
RetryLoop,
RetryNotifier,
RetryTransition,
RunnerComponentFactory,
RunnerComponents,
RunnerLogger,
RSpecAdapter
].freeze
- EVENT_SCHEMA_VERSION =
1
- VERSION =
'1.0.0'
Class Method Summary
collapse
Class Method Details
.auto_install_disabled? ⇒ Boolean
85
86
87
|
# File 'lib/rspec/rewind/core.rb', line 85
def auto_install_disabled?
%w[0 false no off].include?(ENV.fetch('RSPEC_REWIND_AUTO_INSTALL', '').downcase)
end
|
.close_reporter ⇒ Object
89
90
91
92
93
94
95
96
|
# File 'lib/rspec/rewind/core.rb', line 89
def close_reporter
reporter = configuration.flaky_reporter
lifecycle_error = reporter_lifecycle_error(reporter)
publish_retry_summary
enforce_flaky_threshold!
raise lifecycle_error if lifecycle_error && configuration.strict_callbacks
end
|
.configuration ⇒ Object
40
41
42
|
# File 'lib/rspec/rewind/core.rb', line 40
def configuration
@configuration ||= Configuration.new
end
|
44
45
46
|
# File 'lib/rspec/rewind/core.rb', line 44
def configure
yield(configuration)
end
|
.enforce_flaky_threshold! ⇒ Object
112
113
114
115
116
117
|
# File 'lib/rspec/rewind/core.rb', line 112
def enforce_flaky_threshold!
count = configuration.retry_summary.flaky_examples
return unless (configuration.fail_on_flaky && count.positive?) || threshold_exceeded?(count)
raise FlakyThresholdExceeded, "rspec-rewind observed #{count} flaky example(s)"
end
|
.install! ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/rspec/rewind/core.rb', line 52
def install!
return false if installed?
warn_on_retry_gem_conflict
::RSpec::Core::Example.include(ExampleMethods)
::RSpec::Core::Example::Procsy.include(ExampleMethods) if defined?(::RSpec::Core::Example::Procsy)
::RSpec.configure do |config|
config.before(:suite) do
RSpec::Rewind.prepare_suite!
end
config.around(:each) do |example|
if example.metadata[:rewind] == false
example.run
else
example.run_with_rewind
end
end
config.after(:suite) do
RSpec::Rewind.close_reporter
end
end
@installed = true
end
|
.installed? ⇒ Boolean
81
82
83
|
# File 'lib/rspec/rewind/core.rb', line 81
def installed?
!!@installed
end
|
.prepare_suite! ⇒ Object
98
99
100
101
|
# File 'lib/rspec/rewind/core.rb', line 98
def prepare_suite!
configuration.retry_summary.reset!
configuration.freeze if configuration.freeze_configuration_at_suite_start
end
|
.publish_retry_summary ⇒ Object
103
104
105
106
107
108
109
110
|
# File 'lib/rspec/rewind/core.rb', line 103
def publish_retry_summary
return unless configuration.display_retry_summary
summary = configuration.retry_summary.to_message(budget: configuration.retry_budget)
::RSpec.configuration.reporter.message(summary)
rescue StandardError
nil
end
|
.reset_configuration! ⇒ Object
48
49
50
|
# File 'lib/rspec/rewind/core.rb', line 48
def reset_configuration!
@configuration = Configuration.new
end
|
.threshold_exceeded?(count) ⇒ Boolean
119
120
121
122
|
# File 'lib/rspec/rewind/core.rb', line 119
def threshold_exceeded?(count)
max = configuration.max_flaky_examples
!max.nil? && count > max
end
|
.warn_on_retry_gem_conflict ⇒ Object
124
125
126
127
128
129
|
# File 'lib/rspec/rewind/core.rb', line 124
def warn_on_retry_gem_conflict
return unless configuration.detect_retry_gem_conflicts
return unless Gem.loaded_specs.key?('rspec-retry') || defined?(::RSpec::Retry)
warn '[rspec-rewind] rspec-retry appears to be loaded; multiple retry hooks can interfere'
end
|