我有登录sign_in
用户的助手。我正在尝试使用一种新方法来确保用户使用轮询登录:
def sign_in(user, password = '111111')
# ...
click_button 'sign-in-btn'
eventually(5){ page.should have_content user.username.upcase }
end
这是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)
问题是我的一些测试因错误而失败:
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
我该如何解决?