On Github trianglegrrl / ember-cucumber-pres
Scenario: Creating a post displays the new post Given I visit New Posts And I fill in "Title" with "A new post" And I fill in "Author" with "John Doe" And I press "Create" Then I should see "A new post" within "h1" And I should see "John Doe" within "a[rel=author]"
test("creating a post displays the new post", function(){
visit("/posts/new");
fillIn(".post-title", "A new post");
fillIn(".post-author", "John Doe");
click("button.create");
andThen(function() {
ok(find("h1:contains('A new post')").length, "The post's title should display");
ok(find("a[rel=author]:contains('John Doe')").length, "A link to the author should display");
});
});
patiently do click_link(link) end
When /^(?:|I )follow "([^"]*)"$/ do |link|
patiently do
click_link(link)
end
end
def wait_for_ember_application_to_load using_wait_time 20 do patiently do find ".ember-application" end end wait_for_ember_run_loop_to_complete # Then a miracle happens end
$(function() {
var body, doc;
body = $('body');
doc = $(document);
doc.ajaxStart(function() {
return body.addClass('ajax-in-progress').removeClass('ajax-quiet');
});
return doc.ajaxStop(function() {
return body.addClass('ajax-quiet').removeClass('ajax-in-progress');
});
});
Ember.run.hasScheduledTimers()
Ember.run.currentRunLoop
def wait_for_ember_run_loop_to_complete
2000.times do #this means up to 20 seconds
return if page.evaluate_script "'undefined' == typeof window.jQuery"
return if page.evaluate_script "$('body').hasClass('ajax-quiet') && (typeof Ember === 'object') && !Ember.run.hasScheduledTimers() && !Ember.run.currentRunLoop"
sleep 0.01
end
end
jQuery.active === 0 && // Is there a pending Ajax request (typeof Ember === 'object') && // Does this page have Ember? !Ember.run.hasScheduledTimers() && !Ember.run.currentRunLoop
AfterStep '@ember-fuckery' do wait_for_ember_run_loop_to_complete end