This file contains 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("Hide called only once if triggered multiple times", function(){ | |
var deferred = $.Deferred(); | |
this.mock($.prototype).expects('hide') | |
.withArgs(2000) | |
.once() // this once assertion will verify hide was called only once during the test | |
.returns(deferred); | |
hideLink(); | |
QUnit.equal($('#hide-status').text(), 'Link hiding in-progress'); | |
hideLink(); //runs the second time after .hide() was called |
This file contains 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("In-progress message visible once Deferred is resolved", function(){ | |
var deferred = $.Deferred(); | |
this.mock($.prototype).expects('hide') | |
.withArgs(2000) | |
.once() | |
.returns(deferred); | |
hideLink(); | |
// using our deferred will keep the status from updating | |
QUnit.equal($('#hide-status').text(), 'Link hiding in-progress'); |
This file contains 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("Test text confirmation after hide()", { | |
setup: function() { | |
var $fixture = $('#qunit-fixture'); | |
$fixture.append('\ | |
<a href="#" id="hide-link">Click me to hide</a>\ | |
<span id="hide-status"></span>\ | |
'); | |
} | |
}); |
This file contains 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
$( function() { | |
$('#hide-link').on('click', hideLink); | |
}); | |
var hideLink = function() { | |
$('#hide-link').hide( 2000 ).promise() | |
.done(function() { | |
$('#hide-status').text('Link finished hiding'); | |
}); | |
}; |
This file contains 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("Using the Deferred to trigger fail", function() { | |
// ... | |
submitCancel(); | |
QUnit.equal($('#cancel-status').text(), ''); | |
deferred.reject(); // rejecting the deferred triggers fail callback | |
QUnit.equal($('#cancel-status').text(), 'cancel failed'); | |
}); |
This file contains 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("Using the deferred to trigger done for success status", function() { | |
// ... | |
submitCancel(); | |
QUnit.equal($('#cancel-status').text(), ''); | |
// resolving the deferred with an object with the status | |
deferred.resolve({status: "success"}); | |
QUnit.equal($('#cancel-status').text(), 'cancel status: cancel finished'); | |
}); |
This file contains 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("Test Ajax post using deferred object", { | |
setup: function() { | |
var $fixture = $('#qunit-fixture'); | |
$fixture.append('<span id="cancel-status"></span>'); | |
} | |
}); | |
test("Mocking the post call", function() { | |
var deferred = $.Deferred(); |
This file contains 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
$( function() { | |
$('#cancel-link').on('click', submitCancel); | |
}); | |
var submitCancel = function() { | |
return $.post('/cancel-application', {}) | |
.done(function() { $('#cancel-status').text('cancel successful') }) | |
.fail(function() { $('#cancel-status').text('cancel failed') }); | |
}; |
This file contains 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
class BoggleBoard | |
def initialize(board) | |
@board = board | |
end | |
def create_word(*coords) | |
coords.map { |coord| @board[coord.first][coord.last]}.join("") | |
end | |