Last active
August 29, 2015 14:21
-
-
Save bnorton/9c7644deb97f53b789a4 to your computer and use it in GitHub Desktop.
Ember.js meet Capybara
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
<!-- ... --> | |
<%= javascript_include_tag 'test' if Rails.env.test? %> | |
<!-- ... --> |
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
module RequestHelper | |
def self.included(base) | |
base.send(:include, InstanceMethods) | |
end | |
module InstanceMethods | |
## | |
# Wait up to 3 seconds for asyncronous action processing to complete | |
def wait_for_async | |
start_time = Time.now | |
loop do | |
break if page.evaluate_script('Object.keys(test.ajaxRequests).length == 0 && !Ember.run.hasScheduledTimers() && !Ember.run.currentRunLoop') | |
raise "Waited too long for ajax requests to finish #{page.evaluate_script('JSON.stringify(test.ajaxRequests)')} - #{page.evaluate_script('!Ember.run.hasScheduledTimers()')} - #{page.evaluate_script('!Ember.run.currentRunLoop')}" if (Time.now - start_time) > 3 | |
sleep 0.1 | |
end | |
end | |
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
# ... | |
RSpec.configure do |config| | |
config.include RequestHelper, :type => :feature | |
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
test = { | |
ajaxRequests: {} | |
}; | |
$(document).on('ajaxSend', function(e, xhr, options) { | |
test.ajaxRequests[options.url] = true; | |
}).on('ajaxComplete', function(e, xhr, options) { | |
delete test.ajaxRequests[options.url]; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment