Skip to content

Instantly share code, notes, and snippets.

View cjohansen's full-sized avatar

Christian Johansen cjohansen

View GitHub Profile
(defun git-walk (direction)
(interactive)
(shell-command (concat "git walk " direction))
(revert-buffer nil t))
(defun git-walk-next ()
(interactive)
(git-walk "next"))
(defun git-walk-prev ()
RATIONALE =<<_END
The case for a maybe:
We all know true and false, right? Larry Wall once said that truth should be
considered evident; therefore anything in Perl is either true or false, along with
anything else it may be. Truth is just an aspect.
And we use it easily, with the if/else construct:
if something
do_something
describe("My webservices AJAX module", function () {
var server;
beforeEach(function () {
server = sinon.useFakeServer();
server.respondWith("GET", "Products.asmx",
[200, { "Content-Type": "application/json" }, "{ 'some': 'data' }"]);
});
afterEach(function () {
var mylib = {};
mylib.format = (function () {
function format(object) {
if (Object.prototype.toString.call(objec) == "[object Array]") {
return format.array(object);
}
if (typeof object == "function") {
return format.func(object);
@cjohansen
cjohansen / gist:739589
Created December 13, 2010 20:55
Showing how to fake server requests with Sinon.JS and Jasmine
/*
Load Sinon.JS in the SpecRunner:
<script type="text/javascript" src="lib/jasmine-1.0.1/jasmine.js"></script>
<script type="text/javascript" src="lib/jasmine-1.0.1/jasmine-html.js"></script>
<script type="text/javascript" src="sinon-1.0.0.js"></script>
<script type="text/javascript" src="sinon-ie-1.0.0.js"></script>
http://cjohansen.no/sinon/
*/
@cjohansen
cjohansen / gist:739597
Created December 13, 2010 21:00
Mocking jQuery.ajax with Sinon.JS
describe("SinonMockJQAjaxWithJasmine", function() {
it("should mock a jQuery ajax request", sinon.test(function () {
this.mock(jQuery).expects("ajax").once();
jQuery.ajax({
url: "/something"
});
}));
it("should fail when expectations are not met", sinon.test(function () {
@cjohansen
cjohansen / gist:740089
Created December 14, 2010 06:55
Jasmine SpecRunner.html to run Sinon.JS/Jasmine example
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Jasmine Test Runner</title>
<link rel="stylesheet" type="text/css" href="lib/jasmine-1.0.1/jasmine.css">
<script type="text/javascript" src="lib/jasmine-1.0.1/jasmine.js"></script>
<script type="text/javascript" src="lib/jasmine-1.0.1/jasmine-html.js"></script>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="sinon-1.0.0.js"></script>
package com.simplehttp;
import java.net.URI;
import java.net.URISyntaxException;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.EntityUtils;
production: &development
settings: here
development:
<<: *production
test:
test: settings here
TestCase("AjaxTest", sinon.testCase({
testJSONResponse: function () {
this.server.respondWith(
"POST", /post.*/,
[200, { "Content-Type": "application/json"},
'{ "Exception":"", "Success":"true", "ValidationResult":"" }']);
$.post("/post", "data=here", function (data) {
jstestdriver.console.log(typeof data, data);
}, "json");