Skip to content

Instantly share code, notes, and snippets.

@rodrigomanhaes
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rodrigomanhaes/4aa5c9efa3ddcee12850 to your computer and use it in GitHub Desktop.
Save rodrigomanhaes/4aa5c9efa3ddcee12850 to your computer and use it in GitHub Desktop.
require 'rails_helper'
feature 'select2' do
scenario 'select2', js: true do
5.times { create(:disciplina) }
visit new_disciplina_path
execute_script("$('.disciplina_pre_requisitos .select2-input').val('ABC')")
execute_script("$('.disciplina_pre_requisitos .select2-container').select2('open')")
wait_for_ajax
find('.select2-results li:first-child').click
click_button 'Salvar'
end
end
require 'timeout'
module WaitForAjax
def wait_for_ajax
Timeout.timeout(Capybara.default_wait_time) do
loop do
sleep 0.1
break if finished_all_ajax_requests?
end
end
end
def finished_all_ajax_requests?
page.evaluate_script('jQuery.active').zero?
end
end
RSpec.configure do |config|
config.include WaitForAjax
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment