Wait for requests after each Spinach scenario instead of feature

This commit is contained in:
Douwe Maan 2017-05-12 17:10:12 -05:00
parent ec1a3c093f
commit 718350dc9f
2 changed files with 3 additions and 8 deletions

View file

@ -30,8 +30,8 @@ Spinach.hooks.before_run do
include FactoryGirl::Syntax::Methods include FactoryGirl::Syntax::Methods
end end
Spinach.hooks.after_feature do |feature_data| Spinach.hooks.after_scenario do |scenario_data, step_definitions|
if feature_data.scenarios.flat_map(&:tags).include?('javascript') if scenario_data.tags.include?('javascript')
include WaitForRequests include WaitForRequests
wait_for_requests_complete wait_for_requests_complete
end end

View file

@ -10,17 +10,12 @@ module WaitForRequests
def wait_for_requests_complete def wait_for_requests_complete
Gitlab::Testing::RequestBlockerMiddleware.block_requests! Gitlab::Testing::RequestBlockerMiddleware.block_requests!
wait_for('pending AJAX requests complete') do wait_for('pending AJAX requests complete') do
Gitlab::Testing::RequestBlockerMiddleware.num_active_requests.zero? && Gitlab::Testing::RequestBlockerMiddleware.num_active_requests.zero?
finished_all_requests?
end end
ensure ensure
Gitlab::Testing::RequestBlockerMiddleware.allow_requests! Gitlab::Testing::RequestBlockerMiddleware.allow_requests!
end end
def finished_all_requests?
finished_all_ajax_requests? && finished_all_vue_resource_requests?
end
# Waits until the passed block returns true # Waits until the passed block returns true
def wait_for(condition_name, max_wait_time: Capybara.default_max_wait_time, polling_interval: 0.01) def wait_for(condition_name, max_wait_time: Capybara.default_max_wait_time, polling_interval: 0.01)
wait_until = Time.now + max_wait_time.seconds wait_until = Time.now + max_wait_time.seconds