### Install RSpec::Retryable Gem Source: https://github.com/gusto/rspec-retryable/blob/main/README.md Add the rspec-retryable gem to your application's Gemfile or install it directly using the gem command. ```bash bundle add rspec-retryable ``` ```bash gem install rspec-retryable ``` -------------------------------- ### Custom Retry Handler Setup Source: https://github.com/gusto/rspec-retryable/blob/main/README.md Define a custom retry handler class with a `call` method to manage retry logic for RSpec examples. Register the handler with RSpec::Retryable.handlers.register. ```ruby require 'rspec/retryable' class SimpleRetryHandler MAX_RETRIES = 2 def initialize # Initialization code here @retries = Hash.new(0) end def call(payload) # use payload to set retry or not based on RSpec example state if @retries[payload.example.id] < MAX_RETRIES # Set `payload.retry` to `true` to enable rspec retry payload.retry = true if payload.state == :failed else # Pass down to next handler yield end end end RSpec::Retryable.bind RSpec::Retryable.handlers.register(SimpleRetryHandler) ``` -------------------------------- ### Require Retry Setup in RSpec Configuration Source: https://github.com/gusto/rspec-retryable/blob/main/README.md Include the custom retry setup file in your RSpec configuration to enable the retry functionality. ```ruby require 'retry_setup' RSpec.configure do |config| # ... some rspec setup end ``` -------------------------------- ### Chaining Multiple Retry Handlers Source: https://github.com/gusto/rspec-retryable/blob/main/README.md Register multiple retry handlers to create a chain of responsibility for processing payloads. This allows for complex retry strategies and conditional retries. ```ruby RSpec::Retryable.bind class FirstRetryHandler def call(payload) puts "-> First handler in" # ... do something based on payload state ... yield puts "<- First handler out" end end # This handler stops retry when expected condition met class SecondRetryHandler def call(payload) puts "-> Second handler in" # ... do something based on payload state ... yield puts "<- Second handler out" end end RSpec::Retryable.handlers.register(FirstRetryHandler) RSpec::Retryable.handlers.register(SecondRetryHandler) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.