Permalink
Browse files

First stab at Blue Ridge testing itself.

  - Added the Screw.Unit tests to Blue Ridge.
  - Added a default rake task that runs its own tests.
  - Changed the command-line test-runner and shell-runner to
    run as plugin or stand-alone.
  - Changed the in-browser test-runner to run as plugin or
    stand-alone.
  - Changed the shell runner to load jQuery 1.3.2 (not 1.2.6).
  - Changed the shell runner to load the jQuery.print.js
    convenience functions.
  - Commented out the supposed-to-fail tests in Screw.Unit behaviors spec.
  - Note that one of the screw.print_spec tests fails in command-line mode.
    (Need an env.js update to fix, most likely?)
  - Big thanks to David Chelimsky for his advice on test suites
    testing themselves!
  • Loading branch information...
Larry Karnowski
Larry Karnowski committed Jul 6, 2009
1 parent b2801ef commit 6199fc5ed2a3b40a6658d1a5f6262eef4222a259
View
@@ -0,0 +1,4 @@
+ENV["BLUE_RIDGE_PREFIX"] = File.dirname(__FILE__)
+import File.dirname(__FILE__) + '/tasks/javascript_testing_tasks.rake'
+
+task :default => "test:javascripts"
View
@@ -26,18 +26,20 @@ function derive_spec_name_from_current_file() {
return file_prefix + "_spec.js";
}
-// require("../../vendor/plugins/blue-ridge/lib/jquery-1.2.6.js");
-require("../../vendor/plugins/blue-ridge/lib/jquery-1.3.2.js");
+var BLUE_RIDGE_LIB_PREFIX = BLUE_RIDGE_LIB_PREFIX || "../../vendor/plugins/blue-ridge/lib/";
-require("../../vendor/plugins/blue-ridge/lib/jquery.fn.js");
-require("../../vendor/plugins/blue-ridge/lib/jquery.print.js");
-require("../../vendor/plugins/blue-ridge/lib/screw.builder.js");
-require("../../vendor/plugins/blue-ridge/lib/screw.matchers.js");
-require("../../vendor/plugins/blue-ridge/lib/screw.events.js");
-require("../../vendor/plugins/blue-ridge/lib/screw.behaviors.js");
-require("../../vendor/plugins/blue-ridge/lib/smoke.core.js");
-require("../../vendor/plugins/blue-ridge/lib/smoke.mock.js");
-require("../../vendor/plugins/blue-ridge/lib/smoke.stub.js");
-require("../../vendor/plugins/blue-ridge/lib/screw.mocking.js");
+// require(BLUE_RIDGE_LIB_PREFIX + "jquery-1.2.6.js");
+require(BLUE_RIDGE_LIB_PREFIX + "jquery-1.3.2.js");
+
+require(BLUE_RIDGE_LIB_PREFIX + "jquery.fn.js");
+require(BLUE_RIDGE_LIB_PREFIX + "jquery.print.js");
+require(BLUE_RIDGE_LIB_PREFIX + "screw.builder.js");
+require(BLUE_RIDGE_LIB_PREFIX + "screw.matchers.js");
+require(BLUE_RIDGE_LIB_PREFIX + "screw.events.js");
+require(BLUE_RIDGE_LIB_PREFIX + "screw.behaviors.js");
+require(BLUE_RIDGE_LIB_PREFIX + "smoke.core.js");
+require(BLUE_RIDGE_LIB_PREFIX + "smoke.mock.js");
+require(BLUE_RIDGE_LIB_PREFIX + "smoke.stub.js");
+require(BLUE_RIDGE_LIB_PREFIX + "screw.mocking.js");
require(derive_spec_name_from_current_file());
View
@@ -8,19 +8,20 @@
print(" To exit type 'exit', 'quit', or 'quit()'.");
print("=================================================");
- var plugin_prefix = "vendor/plugins/blue-ridge/";
- var fixture_file = plugin_prefix + "generators/blue_ridge/templates/application.html";
+ var plugin_prefix = environment["blue.ridge.prefix"] || "vendor/plugins/blue-ridge";
+ var fixture_file = plugin_prefix + "/generators/blue_ridge/templates/application.html";
- load(plugin_prefix + "lib/env.rhino.js");
+ load(plugin_prefix + "/lib/env.rhino.js");
print(" - loaded env.js");
window.location = fixture_file;
print(" - sample DOM loaded");
- // load(plugin_prefix + "lib/jquery-1.3.2.js");
- // print (" jQuery-1.3.2 loaded");
- load(plugin_prefix + "lib/jquery-1.2.6.js");
- print(" - jQuery-1.2.6 loaded");
+ load(plugin_prefix + "/lib/jquery-1.3.2.js");
+ print(" - jQuery-1.3.2 loaded");
+
+ load(plugin_prefix + "/lib/jquery.print.js");
+ print(" - jQuery print lib loaded");
print("=================================================");
})();
View
@@ -25,26 +25,25 @@ var spec_file = arguments[0];
var fixture = "fixtures/" + spec_file.replace(/^(.*?)_spec\.js$/, "$1.html");
print("Running " + spec_file + " with fixture '" + fixture + "'...");
-var RAILS_ROOT_PREFIX = "../../";
-var PLUGIN_PREFIX = RAILS_ROOT_PREFIX + "/vendor/plugins/blue-ridge/";
+var PLUGIN_PREFIX = environment["blue.ridge.prefix"] || "../../vendor/plugins/blue-ridge";
-load(PLUGIN_PREFIX + "lib/env.rhino.js");
+load(PLUGIN_PREFIX + "/lib/env.rhino.js");
window.location = fixture;
-// load(PLUGIN_PREFIX + "lib/jquery-1.2.6.js");
-load(PLUGIN_PREFIX + "lib/jquery-1.3.2.js");
-
-load(PLUGIN_PREFIX + "lib/jquery.fn.js");
-load(PLUGIN_PREFIX + "lib/jquery.print.js");
-load(PLUGIN_PREFIX + "lib/screw.builder.js");
-load(PLUGIN_PREFIX + "lib/screw.matchers.js");
-load(PLUGIN_PREFIX + "lib/screw.events.js");
-load(PLUGIN_PREFIX + "lib/screw.behaviors.js");
-load(PLUGIN_PREFIX + "lib/smoke.core.js");
-load(PLUGIN_PREFIX + "lib/smoke.mock.js");
-load(PLUGIN_PREFIX + "lib/smoke.stub.js");
-load(PLUGIN_PREFIX + "lib/screw.mocking.js");
-load(PLUGIN_PREFIX + "lib/consoleReportForRake.js");
+// load(PLUGIN_PREFIX + "/lib/jquery-1.2.6.js");
+load(PLUGIN_PREFIX + "/lib/jquery-1.3.2.js");
+
+load(PLUGIN_PREFIX + "/lib/jquery.fn.js");
+load(PLUGIN_PREFIX + "/lib/jquery.print.js");
+load(PLUGIN_PREFIX + "/lib/screw.builder.js");
+load(PLUGIN_PREFIX + "/lib/screw.matchers.js");
+load(PLUGIN_PREFIX + "/lib/screw.events.js");
+load(PLUGIN_PREFIX + "/lib/screw.behaviors.js");
+load(PLUGIN_PREFIX + "/lib/smoke.core.js");
+load(PLUGIN_PREFIX + "/lib/smoke.mock.js");
+load(PLUGIN_PREFIX + "/lib/smoke.stub.js");
+load(PLUGIN_PREFIX + "/lib/screw.mocking.js");
+load(PLUGIN_PREFIX + "/lib/consoleReportForRake.js");
load(spec_file);
jQuery(window).trigger("load");
@@ -1,5 +1,5 @@
-plugin_prefix = "#{RAILS_ROOT}/vendor/plugins/blue-ridge"
-rhino_command = "java -jar #{plugin_prefix}/lib/js.jar -w -debug"
+plugin_prefix = ENV["BLUE_RIDGE_PREFIX"] || "#{RAILS_ROOT}/vendor/plugins/blue-ridge"
+rhino_command = "java -Dblue.ridge.prefix=\"#{plugin_prefix}\" -jar #{plugin_prefix}/lib/js.jar -w -debug"
test_runner_command = "#{rhino_command} #{plugin_prefix}/lib/test_runner.js"
def find_base_dir
View
Binary file not shown.
View
Binary file not shown.
@@ -0,0 +1,14 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+
+<head>
+ <title>Screw.Unit Behaviors | JavaScript Testing Results</title>
+ <link rel="stylesheet" href="../../../generators/blue_ridge/templates/screw.css" type="text/css" charset="utf-8" />
+ <script type="text/javascript" charset="utf-8">var BLUE_RIDGE_LIB_PREFIX = "../../lib/";</script>
+ <script type="text/javascript" src="../../../lib/blue-ridge.js"></script>
+</head>
+
+<body>
+ <!-- Put any HTML fixture elements here. -->
+</body>
+</html>
@@ -0,0 +1,14 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+
+<head>
+ <title>Screw.Unit Matchers | JavaScript Testing Results</title>
+ <link rel="stylesheet" href="../../../generators/blue_ridge/templates/screw.css" type="text/css" charset="utf-8" />
+ <script type="text/javascript" charset="utf-8">var BLUE_RIDGE_LIB_PREFIX = "../../lib/";</script>
+ <script type="text/javascript" src="../../../lib/blue-ridge.js"></script>
+</head>
+
+<body>
+ <!-- Put any HTML fixture elements here. -->
+</body>
+</html>
@@ -0,0 +1,14 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+
+<head>
+ <title>Screw.Unit Print | JavaScript Testing Results</title>
+ <link rel="stylesheet" href="../../../generators/blue_ridge/templates/screw.css" type="text/css" charset="utf-8" />
+ <script type="text/javascript" charset="utf-8">var BLUE_RIDGE_LIB_PREFIX = "../../lib/";</script>
+ <script type="text/javascript" src="../../../lib/blue-ridge.js"></script>
+</head>
+
+<body>
+ <!-- Put any HTML fixture elements here. -->
+</body>
+</html>
@@ -0,0 +1,192 @@
+Screw.Unit(function() {
+ var global_before_invoked = false, global_after_invoked = false;
+ before(function() { global_before_invoked = true });
+ after(function() { global_after_invoked = true });
+
+ describe('Behaviors', function() {
+ describe('#run', function() {
+ describe("elapsed time", function() {
+ it("displays the elapsed time after the Suite finishes", function() {
+ var status = $(".status");
+ status.fn("display");
+ var time_elapsed_matches = /([0-9]+\.[0-9]+) seconds/.exec(status.html());
+ var time_elapsed = parseFloat(time_elapsed_matches[1]);
+ expect(time_elapsed > 0.0).to(be_true);
+ });
+ });
+
+ describe("a simple [describe]", function() {
+ it("invokes the global [before] before an [it]", function() {
+ expect(global_before_invoked).to(equal, true);
+ global_before_invoked = false;
+ });
+
+ it("invokes the global [before] before each [it]", function() {
+ expect(global_before_invoked).to(equal, true);
+ global_after_invoked = false;
+ });
+
+ it("invokes the global [after] after an [it]", function() {
+ expect(global_after_invoked).to(equal, true);
+ });
+ });
+
+ describe("a [describe] with a [before] and [after] block", function() {
+ var before_invoked = false, after_invoked = false;
+ before(function() { before_invoked = true });
+ after(function() { after_invoked = true });
+
+ describe('[after] blocks', function() {
+ it("does not invoke the [after] until after the first [it]", function() {
+ expect(after_invoked).to(equal, false);
+ });
+
+ it("invokes the [after] after the first [it]", function() {
+ expect(after_invoked).to(equal, true);
+ after_invoked = false;
+ });
+
+ it("invokes the [after] after each [it]", function() {
+ expect(after_invoked).to(equal, true);
+ });
+ });
+
+ describe('[before] blocks', function() {
+ it("invokes the [before] before an it", function() {
+ expect(before_invoked).to(equal, true);
+ before_invoked = false;
+ });
+
+ it("invokes the [before] before each it", function() {
+ expect(before_invoked).to(equal, true);
+ });
+ });
+ });
+
+ describe("A [describe] with two [before] and two [after] blocks", function() {
+ var before_invocations = [], after_invocations = [];
+ before(function() { before_invocations.push('before 1') });
+ before(function() { before_invocations.push('before 2') });
+
+ after(function() { after_invocations.push('after 1') });
+ after(function() { after_invocations.push('after 2') });
+
+ it("invokes the [before]s in lexical order before each [it]", function() {
+ expect(before_invocations).to(equal, ['before 1', 'before 2']);
+ });
+
+ it("invokes the [afters]s in lexical order after each [it]", function() {
+ expect(after_invocations).to(equal, ['after 1', 'after 2']);
+ });
+ });
+
+ describe("A describe with a nested describe", function() {
+ var before_invocations = [], after_invocations = [];
+ before(function() {
+ before_invocations = [];
+ before_invocations.push("outermost before");
+ });
+
+ after(function() {
+ after_invocations = [];
+ after_invocations.push("outermost after");
+ });
+
+ it("outside a nested [describe], does not invoke any of the nested's [before]s", function() {
+ expect(before_invocations).to(equal, ["outermost before"]);
+ });
+
+ it("outside a nested [describe], does not invoke any of the nested's [after]s", function() {
+ expect(after_invocations).to(equal, ["outermost after"]);
+ });
+
+ describe("a nested [describe]", function() {
+ before(function() {
+ before_invocations.push("inner before");
+ });
+
+ after(function() {
+ after_invocations.push("inner after");
+ });
+
+ it("runs [before]s in the parent [describe] before each [it]", function() {
+ expect(before_invocations).to(equal, ["outermost before", "inner before"]);
+ });
+
+ it("runs [after]s in the parent [describe] after each [it]", function() {
+ expect(after_invocations).to(equal, ["outermost after", "inner after"]);
+ });
+
+ describe("a doubly nested [describe]", function() {
+ before(function() {
+ before_invocations.push('innermost before');
+ });
+
+ after(function() {
+ after_invocations.push('innermost after');
+ });
+
+ describe('[before] blocks', function() {
+ it("runs [before]s in all ancestors before an [it]", function() {
+ expect(before_invocations).to(equal, ["outermost before", "inner before", "innermost before"]);
+ });
+
+ it("runs [before]s in all ancestors before each [it]", function() {
+ expect(before_invocations).to(equal, ["outermost before", "inner before", "innermost before"]);
+ });
+ });
+
+ describe('[after] blocks', function() {
+ it("runs [after]s in all ancestors after an [it]", function() {
+ expect(after_invocations).to(equal, ["outermost after", "inner after", "innermost after"]);
+ });
+
+ it("runs [after]s in all ancestors after each [it]", function() {
+ expect(after_invocations).to(equal, ["outermost after", "inner after", "innermost after"]);
+ });
+ });
+ });
+ });
+ });
+
+ // LJK: commented-out this section because it's meant to fail; but we want
+ // to have a "green" build when running via continuous integration.
+ // Need to find a way to test a failure without creating a "red" build.
+ //
+ // describe("A describe block with exceptions", function() {
+ // var after_invoked = false;
+ // after(function() {
+ // after_invoked = true;
+ // });
+ //
+ // describe("an exception in a test", function() {
+ // it("fails because it throws an exception", function() {
+ // throw('an exception');
+ // });
+ //
+ // it("invokes [after]s even if the previous [it] raised an exception", function() {
+ // expect(after_invoked).to(equal, true);
+ // });
+ // });
+ // });
+ });
+
+ describe("#selector", function() {
+ describe('a [describe]', function() {
+ it('manufactures a CSS selector that uniquely locates the [describe]', function() {
+ $('.describe').each(function() {
+ expect($($(this).fn('selector')).get(0)).to(equal, $(this).get(0))
+ });
+ });
+ });
+
+ describe('an [it]', function() {
+ it('manufactures a CSS selector that uniquely locates the [it]', function() {
+ $('.it').each(function() {
+ expect($($(this).fn('selector')).get(0)).to(equal, $(this).get(0))
+ });
+ });
+ });
+ });
+ });
+});
Oops, something went wrong.

0 comments on commit 6199fc5

Please sign in to comment.