Skip to content

Instantly share code, notes, and snippets.

@kyeh
kyeh / test_hide_doubleclick.js
Last active August 29, 2015 14:04
test_hide_doubleclick.js
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
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');
});
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');
});
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();
$( 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') });
};
@kyeh
kyeh / 0.2.1-boggle_class_from_methods.rb
Last active December 27, 2015 15:39 — forked from dbc-challenges/0.2.1-boggle_class_from_methods.rb
phase 0 unit 2 week 1 boggle class challenge
class BoggleBoard
def initialize(board)
@board = board
end
def create_word(*coords)
coords.map { |coord| @board[coord.first][coord.last]}.join("")
end