Permalink
Browse files

Added Riot.load() and Riot.require()

  • Loading branch information...
Alex Young
Alex Young committed Feb 27, 2010
1 parent 3ea99a8 commit da38a48c390e457598202809b902419efafdc09d
Showing with 479 additions and 399 deletions.
  1. +46 −1 README.textile
  2. +433 −398 riot.js
View
@@ -47,11 +47,56 @@ h3. Assertions
h3. Riot.run
-<code>Riot.run(function() { // your tests });</code> just adds your tests to <code>window.onload</code>. If there's already an <code>onload</code> handler it'll prepend it. If there's no <code>window</code> it will just run the tests.
+<code>Riot.run(function() { // your tests });</code> just adds your tests to <code>window.onload</code>. If there's already an <code>onload</code> handler it won't add itself. If there's no <code>window</code> it will just run the tests.
+
+<code>Riot.load()</code> can be used to load required scripts in a browser or interpreter. <code>Riot.require()</code> only loads files once by keeping a record of files that have already been loaded.
It can also be called with no parameters to run tests defined with <code>Riot.context</code>. This can be used to create a set of files with tests inside a <code>Riot.context</code> for each file
h3. Packaging
Packaged as a RubyGem usable via "XPCOMCore-RubyGems":http://github.com/conflagrationjs/xpcomcore-rubygem -- "riotjs-xpcc":http://github.com/conflagrationjs/riotjs-xpcc.
+h3. Writing a test for a browser AND interpreter
+
+My current pattern looks like this:
+
+<pre>
+load('riot.js');
+Riot.require('../turing.core.js');
+Riot.require('../turing.oo.js');
+Riot.require('fixtures/example_classes.js');
+
+Riot.context('turing.oo.js', function() {
+ // Tests go here
+});
+
+Riot.run();
+</pre>
+
+<pre>
+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+ &lt;head&gt;
+ &lt;title&gt;Riot&lt;/title&gt;
+ &lt;style&gt;
+p.pass { color: green; font-weight: bold; margin: 0 }
+p.fail { color: red; font-weight: bold; margin: 0 }
+#test-results ul { margin-bottom: 1em }
+ &lt;/style&gt;
+ &lt;script type=&quot;text/javascript&quot; src=&quot;riot.js&quot;&gt;&lt;/script&gt;
+ &lt;script type=&quot;text/javascript&quot; src=&quot;core_test.js&quot;&gt;&lt;/script&gt;
+ &lt;script type=&quot;text/javascript&quot; src=&quot;oo_test.js&quot;&gt;&lt;/script&gt;
+ &lt;/head&gt;
+ &lt;body&gt;
+ &lt;div id=&quot;test-results&quot;&gt;&lt;/div&gt;
+ &lt;/body&gt;
+&lt;/html&gt;
+</pre>
+
+Note:
+
+* <code>load()</code> is no-op'd in browsers if it doesn't exist by Riot
+* <code>Riot.run()</code> will only run once, so you can include multiple Riot test files
+* Specifying <code>Riot.run()</code> at the end of each test file lets you run that file with <code>js Riot.run()</code> in the console
+
Oops, something went wrong.

0 comments on commit da38a48

Please sign in to comment.