Permalink
Browse files

Handle multiple spec files.

  • Loading branch information...
1 parent 59cda03 commit 610d2e94a6203b0e9b134237b7b8ec4aa41e409a @btakita btakita committed Apr 27, 2008
Showing with 57 additions and 15 deletions.
  1. +23 −3 lib/screw.assets.js
  2. +25 −11 lib/screw.builder.js
  3. +7 −0 spec/anotherfile_spec.js
  4. +1 −0 spec/screwunit_spec.html
  5. +1 −1 spec/screwunit_spec.js
View
@@ -4,22 +4,42 @@
var required_paths = [];
var included_stylesheets = {};
var cache_buster = parseInt(new Date().getTime()/(1*1000));
-
- Screw.Assets.require = function(javascript_path, onload) {
+
+ var base_require = function(javascript_path, onload, inject_js) {
if(!required_paths[javascript_path]) {
var full_path = javascript_path + ".js";
if (Screw.Assets.use_cache_buster) {
full_path += '?' + cache_buster;
}
- document.write("<script src='" + full_path + "' type='text/javascript'></script>");
+ inject_js(full_path);
if(onload) {
var scripts = document.getElementsByTagName('script');
scripts[scripts.length-1].onload = onload;
}
required_paths[javascript_path] = true;
}
+ }
+
+ Screw.Assets.require = function(javascript_path, onload) {
+ base_require(javascript_path, onload, function(full_path) {
+ document.write("<script src='" + full_path + "' type='text/javascript'></script>");
+ });
};
+ Screw.Assets.require_using_eval = function(javascript_path, onload) {
+ base_require(javascript_path, onload, function(full_path) {
+ $.ajax({
+ type: "GET",
+ url: full_path,
+ dataType: "script",
+ async: false,
+ success: function(js) {
+ eval(js);
+ }
+ });
+ });
+ }
+
Screw.Assets.stylesheet = function(stylesheet_path) {
if(!included_stylesheets[stylesheet_path]) {
var full_path = stylesheet_path + ".css";
View
@@ -1,22 +1,36 @@
var Screw = {
- Unit: function(fn) {
- var contents = fn.toString().match(/^[^\{]*{((.*\n*)*)}/m)[1];
- var fn = new Function("matchers", "specifications",
+ Unit: function(suite) {
+ var contents = suite.toString().match(/^[^\{]*{((.*\n*)*)}/m)[1];
+ var suite = new Function("matchers", "specifications",
"with (specifications) { with (matchers) { " + contents + " } }"
);
+ if(!Screw.first_suite_loaded) {
+ $(function() {
+ Screw.Specifications.context.push(
+ $('body')
+ .append($('<h3 class="status">'))
+ .append($('<ul class="describes">'))
+ );
+ })
+ Screw.first_suite_loaded = true;
+ }
+
+ Screw.last_suite = suite;
$(function() {
- Screw.Specifications.context.push(
- $('body')
- .append($('<h3 class="status">'))
- .append($('<ul class="describes">'))
- );
- fn.call(this, Screw.Matchers, Screw.Specifications);
- $(Screw).trigger('loaded');
- });
+ suite.call(this, Screw.Matchers, Screw.Specifications);
+ if(Screw.last_suite == suite) {
+ $(Screw).trigger('loaded')
+ }
+ })
},
+ first_suite_loaded: false,
+ last_suite: null,
Specifications: {
context: [],
+ require: function(path) {
+ Screw.Assets.require_using_eval(path);
+ },
describe: function(name, fn) {
var describe = $('<li class="describe">');
$('<h1>').text(name).appendTo(describe);
View
@@ -0,0 +1,7 @@
+Screw.Unit(function() {
+ describe("Another file", function() {
+ it("runs in the same suite", function() {
+ expect(true).to(equal, true);
+ });
+ });
+});
View
@@ -10,6 +10,7 @@
<script type="text/javascript">
stylesheet("../lib/screw");
require("screwunit_spec");
+ require("anotherfile_spec");
</script>
</head>
<body></body>
View
@@ -7,7 +7,7 @@ Screw.Unit(function() {
});
it("equal matches Arrays with the same elements", function() {
- expect([1, 2, 4]).to(equal, [1, 2, 3]);
+ z
expect([1, 2, 3]).to_not(equal, [3, 2, 1]);
});
});

0 comments on commit 610d2e9

Please sign in to comment.