module XamarinTestCloud module Cukes module Retriable class Error < StandardError end def method_that_raises(n) unless n >= 3 raise XamarinTestCloud::Cukes::Retriable::Error, "n: '#{n}' argument is < 3" end true end end end end World(XamarinTestCloud::Cukes::Retriable) Then(/^I call retriable$/) do tries = 5 interval = 0.05 on_retry = Proc.new do |_, try, elapsed_time, next_interval| if elapsed_time && next_interval puts "Updating device state attempt #{try} failed in '#{elapsed_time}'; will retry in '#{next_interval}'" else puts "Updating device state attempt #{try} failed; will retry in #{interval}" end end on_opts = { :on_retry => on_retry, :on => [XamarinTestCloud::Cukes::Retriable::Error] } retry_opts = XamarinTestCloud::RetriableOptions.tries_and_interval(tries, interval) opts = on_opts.merge(retry_opts) counter = 0 Retriable.retriable(opts) do begin method_that_raises(counter) ensure counter = counter + 1 end end end