Como faço para corrigir meu erro de expectativa de pepino ao fazer polling?

Eu tenho o ajudantesign_in que assina um usuário. Eu estou tentando usar uma nova abordagem para se certificar de que o usuário entrou usando o polling:

def sign_in(user, password = '111111')
  # ...
  click_button 'sign-in-btn'

  eventually(5){ page.should have_content user.username.upcase }
end

E aqui estáeventually:

module AsyncSupport
  def eventually(timeout = 2)
    polling_interval = 0.1
    time_limit = Time.now + timeout

    loop do
      begin
        yield
        rescue Exception => error
      end
      return if error.nil?
      raise error if Time.now >= time_limit
      sleep polling_interval
    end
  end
end

World(AsyncSupport)

O problema é que alguns dos meus testes falham com um erro:

expected to find text "USER_EMAIL_1" in "{\"success\":true,\"redirect_url\":\"/users/1/edit\"}" (RSpec::Expectations::ExpectationNotMetError)
./features/support/spec_helper.rb:25:in `block in sign_in'
./features/support/async_support.rb:8:in `block in eventually'
./features/support/async_support.rb:6:in `loop'
./features/support/async_support.rb:6:in `eventually'
./features/support/spec_helper.rb:23:in `sign_in'
./features/step_definitions/user.steps.rb:75:in `/^I am logged in as a "([^\"]*)"$/'
features/user/edit.feature:8:in `And I am logged in as a "user"'

Failing Scenarios:
cucumber features/user/edit.feature:6 # Scenario: Editing personal data

Como posso consertar isso?

questionAnswers(1)

yourAnswerToTheQuestion