Permalink
Browse files

setting up gh-pages

  • Loading branch information...
1 parent 5db6e07 commit 9ed4c52abf2f1325f30b0b0e3a0a10031830d95a Alex Young committed Oct 18, 2009
Showing with 0 additions and 372 deletions.
  1. +0 −42 README.textile
  2. +0 −273 riot.js
  3. +0 −17 riotjs.html
  4. +0 −40 test.js
View
@@ -1,42 +0,0 @@
-This is a JavaScript implementation of "Riot":http://github.com/thumblemonks/riot/
-
-It will run in a browser or in Rhino.
-
-The tests look like this:
-
-<pre>
-Riot.run(function() {
- context('basic riot functionality', function() {
- given('some simple equality tests', function() {
- asserts('a simple truth test should return true', true).isTrue();
- asserts('isNull is null', null).isNull();
- });
-
- given('another context', function() {
- asserts('equals should compare strings as expected', 'test string').equals('test string');
- });
-
- given('a context concerned with functions', function() {
- asserts('asserts() should allow functions to be compared', function() {
- return 'test string';
- }).equals('test string');
- });
- });
-
- given('yet another context', function() {
- asserts('equals should compare strings as expected', 'test string').equals('test string');
- });
-});
-</pre>
-
-h3. Assertions
-
-* <code>equals</code> - for example, <code>asserts('description').equals('value')</code>
-* <code>isNull</code>
-* <code>isTrue</code>
-* <code>typeOf</code>
-* <code>raises</code>
-
-h3. Aliases
-
-The <code>context</code> and <code>asserts</code> functions are aliased as global methods from the <code>Riot</code> object. If those methods are already used you can use the namespaced methods (like <code>Riot.context</code>).
View
273 riot.js
@@ -1,273 +0,0 @@
-Riot = {
- all_results: [],
- results: [],
- current_context: '',
- debug: false,
- wants_aliases: true,
-
- aliases: {
- 'context': 'Riot.context',
- 'given': 'Riot.context',
- 'asserts': 'Riot.asserts',
- },
-
- Benchmark: {
- results: [],
-
- addResult: function(start, end) {
- this.results.push(end - start);
- },
-
- displayResults: function() {
- var total = 0,
- seconds = 0;
- for (i = 0; i < this.results.length; i++) {
- total += this.results[i];
- }
- seconds = total / 1000;
- return 'Elapsed time: ' + total + 'ms (' + seconds + ' seconds)';
- },
-
- run: function(times, callback) {
- if (Riot.wants_aliases) {
- Riot.alias();
- }
-
- this.results = [];
- for (i = 0; i < times; i++) {
- var start = new Date();
- callback();
- var end = new Date();
- this.addResult(start, end);
- }
- return this.displayResults();
- }
- },
-
- Formatters: {
- HTML: function() {
- function display(html) {
- var results = document.getElementById('test-results');
- results.innerHTML += html;
- }
-
- this.line = function(text) {
- display('<p>' + text + '</p>');
- }
-
- this.pass = function(message) {
- display('<p class="pass">' + message + '</p>');
- }
-
- this.fail = function(message) {
- display('<p class="fail">' + message + '</p>');
- }
-
- this.context = function(name) {
- display('<h3>' + name + '</h3>');
- }
-
- this.separator = function() {
- display('<hr />');
- }
- },
-
- Text: function() {
- function display(text) {
- print(text);
- }
-
- this.line = function(text) {
- display(text);
- }
-
- this.pass = function(message) {
- this.line(" [PASS] " + message);
- }
-
- this.fail = function(message) {
- this.line(" [FAIL] " + message);
- }
-
- this.context = function(name) {
- this.line("* " + name);
- }
-
- this.separator = function() {
- this.line('--------------------------------------------------');
- }
- }
- },
-
- run: function(tests) {
- if (typeof window === 'undefined') {
- Riot.formatter = new Riot.Formatters.Text();
- alert = print;
- Riot._run(tests);
- } else {
- Riot.formatter = new Riot.Formatters.HTML();
- var onload = window.onload;
- window.onload = function() {
- if (onload) window.onload();
- Riot._run(tests);
- }
- }
- },
-
- _run: function(tests) {
- var benchmark = Riot.Benchmark.run(1, tests);
- Riot.formatter.separator();
- Riot.summariseAllResults();
- Riot.formatter.line(benchmark);
- },
-
- alias: function() {
- var errors = '';
- for (var key in this.aliases) {
- try {
- eval(key);
- errors += 'Unable to alias: ' + key + ' as ' + this.aliases[key];
- } catch (exception) {
- eval(key + ' = ' + this.aliases[key]);
- }
- }
-
- if (errors.length > 0) { alert('Riot warning: ' + errors); }
- },
-
- context: function(title, callback) {
- new Context(title, callback).run();
- },
-
- asserts: function(name, result) {
- return new Assertion(name, result);
- },
-
- reset: function() {
- this.results = [];
- },
-
- summariseResults: function() { return this.summarise(this.results); },
- summariseAllResults: function() { return this.summarise(this.all_results); },
-
- summarise: function(results) {
- var passes = 0,
- failures = 0;
- for (i = 0; i < results.length; i++) {
- results[i].pass ? (passes += 1) : (failures += 1);
- }
- this.formatter.line(results.length + ' assertions: ' + failures + ' failures');
- },
-
- addResult: function(context, assertion, pass) {
- var result = {
- assertion: assertion,
- pass: pass,
- context: context
- };
- this.results.push(result);
- this.all_results.push(result);
- }
-};
-
-function Context(name, callback) {
- this.name = name;
- this.callback = callback;
-
- this.run = function() {
- var context = this;
- Riot.current_context = this.name;
- Riot.reset();
- Riot.formatter.context(this.name);
- context.callback();
- Riot.current_context = '';
- Riot.reset();
- }
-}
-
-function Assertion(name, expected) {
- this.name = name;
- this.expectedValue = expected;
-
- this.fail = function(message) {
- Riot.addResult(this.current_context, this.name, false);
- Riot.formatter.fail(message);
- }
-
- this.pass = function() {
- Riot.addResult(this.current_context, this.name, true);
- Riot.formatter.pass(this.name);
- }
-
- this.equals = function(expected) {
- if (expected == this.expected()) {
- this.pass();
- } else {
- this.fail(expected + ' does not equal: ' + this.expected());
- }
- }
-
- this.raises = function(expected) {
- try {
- this.expectedValue();
- } catch (exception) {
- if (expected == exception) {
- this.pass();
- return;
- }
- }
- this.fail('did not raise ' + expected);
- }
-
- this.typeOf = function(expected) {
- var v = this.expected(),
- t = typeof this.expected();
- if (t === 'object') {
- if (v) {
- if (typeof v.length === 'number' &&
- !(v.propertyIsEnumerable('length')) &&
- typeof v.splice === 'function') {
- t = 'array';
- }
- } else {
- t = 'null';
- }
- }
-
- if (t == expected.toLowerCase()) {
- this.pass();
- } else {
- this.fail(expected + ' is not a type of ' + this.expected());
- }
- }
-
- this.kindOf = this.typeOf;
-
- this.isTrue = function() {
- if (this.expected() == true) {
- this.pass();
- } else {
- this.fail('was not true');
- }
- }
-
- this.isNull = function() {
- if (this.expected() === null) {
- this.pass();
- } else {
- this.fail('was not null');
- }
- }
-
- this.expected = function() {
- if (typeof this._expected === 'undefined') {
- if (typeof this.expectedValue === 'function') {
- this._expected = this.expectedValue();
- } else {
- this._expected = this.expectedValue;
- }
- }
-
- return this._expected;
- }
-}
View
@@ -1,17 +0,0 @@
-<!DOCTYPE html>
-<html>
- <head>
- <title>Riot</title>
- <style>
-p.pass { color: green; font-weight: bold; margin: 0 }
-p.fail { color: red; font-weight: bold; margin: 0 }
-#test-results ul { margin-bottom: 1em }
- </style>
- <script type="text/javascript" src="riot.js"></script>
- <script type="text/javascript" src="test.js"></script>
- </head>
- <body>
- <div id="test-results"></div>
- </body>
-</html>
-
View
40 test.js
@@ -1,40 +0,0 @@
-if (typeof load != 'undefined') {
- load('riot.js');
-}
-
-Riot.run(function() {
- context('basic riot functionality', function() {
- given('some simple equality tests', function() {
- asserts('a simple truth test should return true', true).isTrue();
- asserts('isNull is null', null).isNull();
- });
-
- given('another context', function() {
- asserts('equals should compare strings as expected', 'test string').equals('test string');
- });
-
- given('a context concerned with functions', function() {
- asserts('asserts() should allow functions to be compared', function() {
- return 'test string';
- }).equals('test string');
- });
-
- given('some objects that need type checks', function() {
- asserts('a string should be a String', 'String').kindOf('String');
- asserts('an array should be an Array', [1, 2, 3]).kindOf('Array');
- asserts('an array should be an Array', null).typeOf('null');
- asserts('an array should be an Array', null).typeOf('wrong');
- });
-
- given('some exceptions', function() {
- asserts('this should raise ExampleError', function() { throw('ExampleError'); }).raises('ExampleError');
- asserts('this should fail', function() { }).raises('ExampleError');
- asserts('this should fail', function() { throw('AnotherError'); }).raises('ExampleError');
- });
- });
-
- given('yet another context', function() {
- asserts('equals should compare strings as expected', 'test string').equals('test string');
- });
-});
-

0 comments on commit 9ed4c52

Please sign in to comment.