Skip to content
Browse files

Screw requires its own variant of monarch view to prevent conflicts w…

…ith copies of it on the load path of code under test. Using one large queue to run all specs so they run in order and don't contend with one another.
  • Loading branch information...
1 parent 1f89466 commit d4c3892dd88ee35e089d2c39c1ccf94dddb2233a Grockit committed Dec 21, 2009
View
2 client/lib/screw.js
@@ -1,4 +1,4 @@
-//= require <monarch_view>
+//= require <screw.monarch_view>
//= require <jquery.print>
//= require <jquery.cookie>
View
10 client/lib/screw/description.js
@@ -160,6 +160,16 @@ Monarch.constructor("Screw.Description", Screw.RunnableMethods, {
this.afters.push(fn);
},
+ add_to_queue: function(queue) {
+ Monarch.Util.each(this.examples, function(example) {
+ example.add_to_queue(queue);
+ });
+
+ Monarch.Util.each(this.child_descriptions, function(description) {
+ description.add_to_queue(queue);
+ });
+ },
+
run: function() {
var queue = new Monarch.Queue();
Monarch.Util.each(this.examples, function(example) {
View
7 client/lib/screw/example.js
@@ -17,6 +17,13 @@ Monarch.constructor("Screw.Example", Screw.RunnableMethods, {
clone.initialize(this.name, this.fn);
return clone;
},
+
+ add_to_queue: function(queue) {
+ var self = this;
+ queue.add(function() {
+ self.run();
+ });
+ },
run: function() {
try {
View
6 client/lib/screw/interface/runner.js
@@ -101,11 +101,9 @@ Monarch.constructor("Screw.Interface.Runner", Monarch.View.Template, {
var queue = new Monarch.Queue();
this.root.on_example_completed(function() { self.example_completed() } );
-
+
Monarch.Util.each(objects_to_run, function(runnable) {
- queue.add(function() {
- runnable.run();
- });
+ runnable.add_to_queue(queue);
});
queue.start();
View
4 client/spec/description_spec.js
@@ -13,6 +13,10 @@ Screw.Unit(function(c) { with(c) {
description.add_example(this);
});
});
+
+ after(function() {
+ Screw.Monarch.Queue.synchronous = false;
+ });
describe("#initialize", function() {
it("assigns #name", function() {
View
24 client/spec/interface/runner_spec.js
@@ -18,6 +18,10 @@ Screw.Unit(function(c) { with(c) {
mock(Screw.jQuery, 'cookie');
mock(Screw.jQuery, 'ajax');
});
+
+ after(function() {
+ Screw.Monarch.Queue.synchronous = false;
+ });
init(function() {
show = 'all'
@@ -58,24 +62,24 @@ Screw.Unit(function(c) { with(c) {
describe("#run", function() {
context("when passed an array of paths as the run_paths: option", function() {
- it("calls run on the examples or descriptions corresponding to the paths", function() {
- mock(child_description_1, 'run');
- mock(child_description_1_example, 'run');
- mock(child_description_2, 'run');
+ it("calls add_to_queue on the examples or descriptions corresponding to the paths, then starts the queue", function() {
+ mock(child_description_1, 'add_to_queue');
+ mock(child_description_1_example, 'add_to_queue');
+ mock(child_description_2, 'add_to_queue');
view.run([[0, 0], [1]]);
- expect(child_description_1.run).to_not(have_been_called);
- expect(child_description_1_example.run).to(have_been_called, once);
- expect(child_description_2.run).to(have_been_called, once);
+ expect(child_description_1.add_to_queue).to_not(have_been_called);
+ expect(child_description_1_example.add_to_queue).to(have_been_called, once);
+ expect(child_description_2.add_to_queue).to(have_been_called, once);
});
});
context("when passed no run_paths", function() {
- it("calls #run on root", function() {
- mock(root, 'run');
+ it("calls #add_to_queue on root", function() {
+ mock(root, 'add_to_queue');
view.run();
- expect(root.run).to(have_been_called);
+ expect(root.add_to_queue).to(have_been_called);
});
});
});
View
232 client/vendor/monarch_view.js → client/vendor/screw.monarch_view.js
@@ -4542,122 +4542,122 @@ jQuery.extend({
});
- var hex=new Array('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f');
-
-
- function htmlEscape(input)
- {
- var preescape=input;
- var escaped="";
-
- var i=0;
- for(i=0;i<preescape.length;i++)
- {
- escaped=escaped+escapeChar(preescape.charAt(i));
- }
-
- return escaped;
- }
-
- function escapeChar(original)
- {
- var found=true;
- var thechar=original.charCodeAt(0);
- switch(thechar) {
- case '\n': return "<br/>"; break; //newline
- case '\r': break;
- case 60:return "&lt;"; break; //<
- case 62:return "&gt;"; break; //>
- case 38:return "&amp;"; break; //&
- case 34:return "&quot;"; break; //"
- case 198:return "&AElig;"; break; //Æ
- case 193:return "&Aacute;"; break; //Á
- case 194:return "&Acirc;"; break; //Â
- case 192:return "&Agrave;"; break; //À
- case 197:return "&Aring;"; break; //Å
- case 195:return "&Atilde;"; break; //Ã
- case 196:return "&Auml;"; break; //Ä
- case 199:return "&Ccedil;"; break; //Ç
- case 208:return "&ETH;"; break; //Ð
- case 201:return "&Eacute;"; break; //É
- case 202:return "&Ecirc;"; break; //Ê
- case 200:return "&Egrave;"; break; //È
- case 203:return "&Euml;"; break; //Ë
- case 205:return "&Iacute;"; break; //Í
- case 206:return "&Icirc;"; break; //Î
- case 204:return "&Igrave;"; break; //Ì
- case 207:return "&Iuml;"; break; //Ï
- case 209:return "&Ntilde;"; break; //Ñ
- case 211:return "&Oacute;"; break; //Ó
- case 212:return "&Ocirc;"; break; //Ô
- case 210:return "&Ograve;"; break; //Ò
- case 216:return "&Oslash;"; break; //Ø
- case 213:return "&Otilde;"; break; //Õ
- case 214:return "&Ouml;"; break; //Ö
- case 222:return "&THORN;"; break; //Þ
- case 218:return "&Uacute;"; break; //Ú
- case 219:return "&Ucirc;"; break; //Û
- case 217:return "&Ugrave;"; break; //Ù
- case 220:return "&Uuml;"; break; //Ü
- case 221:return "&Yacute;"; break; //Ý
- case 225:return "&aacute;"; break; //á
- case 226:return "&acirc;"; break; //â
- case 230:return "&aelig;"; break; //æ
- case 224:return "&agrave;"; break; //à
- case 229:return "&aring;"; break; //å
- case 227:return "&atilde;"; break; //ã
- case 228:return "&auml;"; break; //ä
- case 231:return "&ccedil;"; break; //ç
- case 233:return "&eacute;"; break; //é
- case 234:return "&ecirc;"; break; //ê
- case 232:return "&egrave;"; break; //è
- case 240:return "&eth;"; break; //ð
- case 235:return "&euml;"; break; //ë
- case 237:return "&iacute;"; break; //í
- case 238:return "&icirc;"; break; //î
- case 236:return "&igrave;"; break; //ì
- case 239:return "&iuml;"; break; //ï
- case 241:return "&ntilde;"; break; //ñ
- case 243:return "&oacute;"; break; //ó
- case 244:return "&ocirc;"; break; //ô
- case 242:return "&ograve;"; break; //ò
- case 248:return "&oslash;"; break; //ø
- case 245:return "&otilde;"; break; //õ
- case 246:return "&ouml;"; break; //ö
- case 223:return "&szlig;"; break; //ß
- case 254:return "&thorn;"; break; //þ
- case 250:return "&uacute;"; break; //ú
- case 251:return "&ucirc;"; break; //û
- case 249:return "&ugrave;"; break; //ù
- case 252:return "&uuml;"; break; //ü
- case 253:return "&yacute;"; break; //ý
- case 255:return "&yuml;"; break; //ÿ
- case 162:return "&cent;"; break; //¢
- default:
- found=false;
- break;
- }
- if(!found)
- {
- if(thechar>127) {
- var c=thechar;
- var a4=c%16;
- c=Math.floor(c/16);
- var a3=c%16;
- c=Math.floor(c/16);
- var a2=c%16;
- c=Math.floor(c/16);
- var a1=c%16;
- return "&#x"+hex[a1]+hex[a2]+hex[a3]+hex[a4]+";";
- }
- else
- {
- return original;
- }
- }
-
-
- }
+ var hex=new Array('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f');
+
+
+ function htmlEscape(input)
+ {
+ var preescape=input;
+ var escaped="";
+
+ var i=0;
+ for(i=0;i<preescape.length;i++)
+ {
+ escaped=escaped+escapeChar(preescape.charAt(i));
+ }
+
+ return escaped;
+ }
+
+ function escapeChar(original)
+ {
+ var found=true;
+ var thechar=original.charCodeAt(0);
+ switch(thechar) {
+ case '\n': return "<br/>"; break; //newline
+ case '\r': break;
+ case 60:return "&lt;"; break; //<
+ case 62:return "&gt;"; break; //>
+ case 38:return "&amp;"; break; //&
+ case 34:return "&quot;"; break; //"
+ case 198:return "&AElig;"; break; //Æ
+ case 193:return "&Aacute;"; break; //Á
+ case 194:return "&Acirc;"; break; //Â
+ case 192:return "&Agrave;"; break; //À
+ case 197:return "&Aring;"; break; //Å
+ case 195:return "&Atilde;"; break; //Ã
+ case 196:return "&Auml;"; break; //Ä
+ case 199:return "&Ccedil;"; break; //Ç
+ case 208:return "&ETH;"; break; //Ð
+ case 201:return "&Eacute;"; break; //É
+ case 202:return "&Ecirc;"; break; //Ê
+ case 200:return "&Egrave;"; break; //È
+ case 203:return "&Euml;"; break; //Ë
+ case 205:return "&Iacute;"; break; //Í
+ case 206:return "&Icirc;"; break; //Î
+ case 204:return "&Igrave;"; break; //Ì
+ case 207:return "&Iuml;"; break; //Ï
+ case 209:return "&Ntilde;"; break; //Ñ
+ case 211:return "&Oacute;"; break; //Ó
+ case 212:return "&Ocirc;"; break; //Ô
+ case 210:return "&Ograve;"; break; //Ò
+ case 216:return "&Oslash;"; break; //Ø
+ case 213:return "&Otilde;"; break; //Õ
+ case 214:return "&Ouml;"; break; //Ö
+ case 222:return "&THORN;"; break; //Þ
+ case 218:return "&Uacute;"; break; //Ú
+ case 219:return "&Ucirc;"; break; //Û
+ case 217:return "&Ugrave;"; break; //Ù
+ case 220:return "&Uuml;"; break; //Ü
+ case 221:return "&Yacute;"; break; //Ý
+ case 225:return "&aacute;"; break; //á
+ case 226:return "&acirc;"; break; //â
+ case 230:return "&aelig;"; break; //æ
+ case 224:return "&agrave;"; break; //à
+ case 229:return "&aring;"; break; //å
+ case 227:return "&atilde;"; break; //ã
+ case 228:return "&auml;"; break; //ä
+ case 231:return "&ccedil;"; break; //ç
+ case 233:return "&eacute;"; break; //é
+ case 234:return "&ecirc;"; break; //ê
+ case 232:return "&egrave;"; break; //è
+ case 240:return "&eth;"; break; //ð
+ case 235:return "&euml;"; break; //ë
+ case 237:return "&iacute;"; break; //í
+ case 238:return "&icirc;"; break; //î
+ case 236:return "&igrave;"; break; //ì
+ case 239:return "&iuml;"; break; //ï
+ case 241:return "&ntilde;"; break; //ñ
+ case 243:return "&oacute;"; break; //ó
+ case 244:return "&ocirc;"; break; //ô
+ case 242:return "&ograve;"; break; //ò
+ case 248:return "&oslash;"; break; //ø
+ case 245:return "&otilde;"; break; //õ
+ case 246:return "&ouml;"; break; //ö
+ case 223:return "&szlig;"; break; //ß
+ case 254:return "&thorn;"; break; //þ
+ case 250:return "&uacute;"; break; //ú
+ case 251:return "&ucirc;"; break; //û
+ case 249:return "&ugrave;"; break; //ù
+ case 252:return "&uuml;"; break; //ü
+ case 253:return "&yacute;"; break; //ý
+ case 255:return "&yuml;"; break; //ÿ
+ case 162:return "&cent;"; break; //¢
+ default:
+ found=false;
+ break;
+ }
+ if(!found)
+ {
+ if(thechar>127) {
+ var c=thechar;
+ var a4=c%16;
+ c=Math.floor(c/16);
+ var a3=c%16;
+ c=Math.floor(c/16);
+ var a2=c%16;
+ c=Math.floor(c/16);
+ var a1=c%16;
+ return "&#x"+hex[a1]+hex[a2]+hex[a3]+hex[a4]+";";
+ }
+ else
+ {
+ return original;
+ }
+ }
+
+
+ }
Monarch = {
constructor: function() {
Monarch.ModuleSystem.constructor.apply(Monarch.ModuleSystem, arguments);
View
46 spec/screw_unit/resources/spec_runner_spec.rb
@@ -0,0 +1,46 @@
+require "#{File.dirname(__FILE__)}/../../screw_unit_spec_helper"
+
+module ScrewUnit
+ module Resources
+ describe SpecRunner do
+ attr_reader :dir, :spec_file_resources, :spec_suite, :asset_manager
+
+ before do
+ @dir = ::File.expand_path(::File.dirname(__FILE__))
+ @asset_manager = Configuration.new.asset_manager
+ asset_manager.add_location("/specs", "#{dir}/file_system_fixtures/specs")
+ @spec_file_resources = Dir.new("/specs", asset_manager).glob("**/*.js")
+ @spec_suite = SpecRunner.new(spec_file_resources, asset_manager)
+ end
+
+ describe "#get" do
+ attr_reader :response_code, :headers, :content
+ before do
+ @response_code, @headers, @content = spec_suite.get
+ end
+
+ it "returns a response code of 200" do
+ response_code.should == 200
+ end
+
+ it "returns a Content-Type header of 'text/html'" do
+ headers['Content-Type'].should == "text/html"
+ end
+
+ it "includes the relative paths of all the screw unit core files" do
+ Dir.new("/screw_unit_core", asset_manager).glob("/**/*.js").each do |core_file_resource|
+ expected_include_tag = %{<script type="text/javascript" src="#{core_file_resource.virtual_path}"></script>}
+ content.should match(/#{expected_include_tag}/)
+ end
+ end
+
+ it "includes the relative paths of all the scripts files with which it was initialized" do
+ spec_file_resources.each do |spec_file_resource|
+ expected_include_tag = %{<script type="text/javascript" src="#{spec_file_resource.virtual_path}"></script>}
+ content.should match(/#{expected_include_tag}/)
+ end
+ end
+ end
+ end
+ end
+end

0 comments on commit d4c3892

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