Last active
August 29, 2015 14:07
-
-
Save rodrigomanhaes/4aa5c9efa3ddcee12850 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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