Question

So i have two calls to a method called retry_with_timeout that takes a block and executes until the block returns true or a value other than nil (i.e false will result in a loop) or until a timeout occurs

Sample class:

def do_the_thing
  retry_with_timeout(10, 5) do
    case something
      when 1
        false
      when 2
        false
      else
         raise
    end
  end

  retry_with_timeout(30, 10) do
    case something_else
      when 1
        false
      when 2
        false
      when 3
        true
      else
         raise
    end
  end
end

Spec class:

it "should pass when the thing is 3" do
  model = test_model #creates a double and stubs all of the necessary common methods

  t_model.stub(:retry_with_timeout).with(10, 5).ordered
  t_model.stub(:retry_with_timeout).with(30, 10).and_yield().ordered

  expect { t_model.do_the_thing }.to be(true)
end

I get an error because the '3' case isn't in the first block, thus the 'else' is called...

I need to skip the first and evaluate in the second block.... I have tried EVERYTHING and I am LOSING MY MIND!!!! Can anyone help me?

Was it helpful?

Solution

Ok, so I've answered my own question... Turns out there are some features that aren't documented... In order to return then yield, one must do it the following way:

t_model.stub(:some_method).and_return("Cool", "Awesome", and_yield(foo))

#Just for informations' sake
t_model.stub(:some_other_method).and_return("FOO", "BAR", raise_error)

its added as a return item for some reason and ISN'T DOCUMENTED ANYWHERE!!!!!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top