Skip to content
Browse files

Added the mocha-LiveScript example.

  • Loading branch information...
1 parent 5537075 commit 51ccc427545778db0d051c62fca14a15f79a2337 @dmohl committed Jun 23, 2012
View
122 example/mocha-LiveScript/lib/example.spec.js
@@ -0,0 +1,122 @@
+(function(){
+ describe("Example Mocha Specifications", function(){
+ var foo;
+ foo = "bar";
+ describe("When testing should equal", function(){
+ return expectThat(function(){
+ return foo.should(equal("bar"));
+ });
+ });
+ describe("When testing shouldnt equal", function(){
+ return expectThat(function(){
+ return foo.shouldnt(equal("baz"));
+ });
+ });
+ describe("When testing for true", function(){
+ expectThat(function(){
+ return (foo === "bar").should(be(true));
+ });
+ return expectThat(function(){
+ return (foo === "baz").shouldnt(be(true));
+ });
+ });
+ describe("When testing for false", function(){
+ expectThat(function(){
+ return (foo === "baz").should(be(false));
+ });
+ return expectThat(function(){
+ return (foo === "bar").shouldnt(be(false));
+ });
+ });
+ describe("When testing to and be", function(){
+ expectThat(function(){
+ return foo.should(be(equal(to("bar"))));
+ });
+ return expectThat(function(){
+ return foo.shouldnt(be(equal(to("bah"))));
+ });
+ });
+ describe("When testing for null or undefined", function(){
+ var testNull, testUndefined;
+ testNull = null;
+ testUndefined = void 8;
+ expectThat(function(){
+ return (testNull === null).should(be(true));
+ });
+ expectThat(function(){
+ return (testNull !== null).shouldnt(be(true));
+ });
+ expectThat(function(){
+ return (testUndefined === void 8).should(be(true));
+ });
+ return expectThat(function(){
+ return (testUndefined === void 8).shouldnt(be(false));
+ });
+ });
+ describe("When testing for throw", function(){
+ expectThat(function(){
+ return function(){
+ throw "test exception";
+ }.should(throwException);
+ });
+ return expectThat(function(){
+ return function(){
+ throw "test exception";
+ }.should(throwException("test exception"));
+ });
+ });
+ describe("When testing for greater than", function(){
+ expectThat(function(){
+ return 10 .should(be(greaterThan(9)));
+ });
+ return expectThat(function(){
+ return 9.1.shouldnt(be(greaterThan(10)));
+ });
+ });
+ describe("When testing for less than", function(){
+ expectThat(function(){
+ return 10 .should(be(lessThan(11)));
+ });
+ return expectThat(function(){
+ return 10.1.shouldnt(be(lessThan(10)));
+ });
+ });
+ describe("When testing for the weekend", function(){
+ var weekend, isWeekend;
+ weekend = ['sat', 'sun'];
+ isWeekend = function(dayOfWeek){
+ switch (false) {
+ case !__in(dayOfWeek, weekend):
+ return true;
+ default:
+ return false;
+ }
+ };
+ return expectThat(function(){
+ return isWeekend(
+ 'sun').should(equal(true));
+ });
+ });
+ return describe("When testing for a weekday", function(){
+ var weekend, isWeekend;
+ weekend = ['sat', 'sun'];
+ isWeekend = function(dayOfWeek){
+ switch (false) {
+ case !__in(dayOfWeek, weekend):
+ return true;
+ default:
+ return false;
+ }
+ };
+ return expectThat(function(){
+ return isWeekend(
+ 'mon').shouldnt(equal(true));
+ });
+ });
+ });
+ function __in(x, arr){
+ var i = 0, l = arr.length >>> 0;
+ while (i < l) if (x === arr[i++]) return true;
+ return false;
+ }
+}).call(this);
View
20 example/mocha-LiveScript/specs.html
@@ -0,0 +1,20 @@
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>Mocha Tests</title>
+ <link rel="stylesheet" href="https://raw.github.com/visionmedia/mocha/master/mocha.css" />
+ <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
+ <script src="https://raw.github.com/visionmedia/mocha/master/mocha.js"></script>
+ <script type="text/javascript" src="../../lib/expectThat.mocha.js"></script>
+ <script>mocha.setup('bdd')</script>
+ <script src="./lib/example.spec.js"></script>
+ <script>
+ $(function () {
+ mocha.run()
+ })
+ </script>
+</head>
+<body>
+ <div id="mocha"></div>
+</body>
+</html>
View
56 example/mocha-LiveScript/specs/example.spec.js.ls
@@ -0,0 +1,56 @@
+describe "Example Mocha Specifications", ->
+ foo = "bar"
+
+ describe "When testing should equal", ->
+ expectThat -> foo.should equal "bar"
+
+ describe "When testing shouldnt equal", ->
+ expectThat -> foo.shouldnt equal "baz"
+
+ describe "When testing for true", ->
+ expectThat -> (foo is "bar").should be true
+ expectThat -> (foo is "baz").shouldnt be true
+
+ describe "When testing for false", ->
+ expectThat -> (foo is "baz").should be false
+ expectThat -> (foo is "bar").shouldnt be false
+
+ describe "When testing to and be", ->
+ expectThat -> foo.should be equal to "bar"
+ expectThat -> foo.shouldnt be equal to "bah"
+
+ describe "When testing for null or undefined", ->
+ testNull = null
+ testUndefined = undefined
+ expectThat -> (testNull is null).should be true
+ expectThat -> (testNull isnt null).shouldnt be true
+ expectThat -> (testUndefined is undefined).should be true
+ expectThat -> (testUndefined is undefined).shouldnt be false
+
+ describe "When testing for throw", ->
+ expectThat -> (-> throw "test exception").should throwException
+ expectThat -> (-> throw "test exception").should throwException "test exception"
+
+ describe "When testing for greater than", ->
+ expectThat -> 10.should be greaterThan 9
+ expectThat -> 9.1.shouldnt be greaterThan 10
+
+ describe "When testing for less than", ->
+ expectThat -> 10.should be lessThan 11
+ expectThat -> 10.1.shouldnt be lessThan 10
+
+ describe "When testing for the weekend", ->
+ weekend = <[ sat sun ]>
+ isWeekend = (dayOfWeek) ->
+ | dayOfWeek in weekend => true
+ | otherwise => false
+
+ expectThat -> ('sun' |> isWeekend).should equal true
+
+ describe "When testing for a weekday", ->
+ weekend = <[ sat sun ]>
+ isWeekend = (dayOfWeek) ->
+ | dayOfWeek in weekend => true
+ | otherwise => false
+
+ expectThat -> ('mon' |> isWeekend).shouldnt equal true

0 comments on commit 51ccc42

Please sign in to comment.
Something went wrong with that request. Please try again.