Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

installed blue-ridge

  • Loading branch information...
commit 58e36d30f4bc29dc7a9ea554fd4afe71990cc2a4 1 parent 639da07
@stuarthalloway authored
Showing with 18,364 additions and 0 deletions.
  1. +15 −0 test/javascript/application_spec.js
  2. +16 −0 test/javascript/fixtures/application.html
  3. +90 −0 test/javascript/fixtures/screw.css
  4. +1 −0  test/javascript/spec_helper.js
  5. +20 −0 vendor/plugins/blue-ridge/LICENSE
  6. +22 −0 vendor/plugins/blue-ridge/LICENSE-Screw.Unit
  7. +22 −0 vendor/plugins/blue-ridge/LICENSE-Smoke
  8. +233 −0 vendor/plugins/blue-ridge/README.markdown
  9. +42 −0 vendor/plugins/blue-ridge/TODO.taskpaper
  10. +18 −0 vendor/plugins/blue-ridge/generators/blue_ridge/blue_ridge_generator.rb
  11. +16 −0 vendor/plugins/blue-ridge/generators/blue_ridge/templates/application.html
  12. +15 −0 vendor/plugins/blue-ridge/generators/blue_ridge/templates/application_spec.js
  13. +90 −0 vendor/plugins/blue-ridge/generators/blue_ridge/templates/screw.css
  14. +1 −0  vendor/plugins/blue-ridge/generators/blue_ridge/templates/spec_helper.js
  15. +30 −0 vendor/plugins/blue-ridge/generators/javascript_spec/javascript_spec_generator.rb
  16. +13 −0 vendor/plugins/blue-ridge/generators/javascript_spec/templates/fixture.html.erb
  17. +10 −0 vendor/plugins/blue-ridge/generators/javascript_spec/templates/javascript_spec.js.erb
  18. +43 −0 vendor/plugins/blue-ridge/lib/blue-ridge.js
  19. +32 −0 vendor/plugins/blue-ridge/lib/consoleReportForRake.js
  20. +8,841 −0 vendor/plugins/blue-ridge/lib/env.rhino.js
  21. +3,549 −0 vendor/plugins/blue-ridge/lib/jquery-1.2.6.js
  22. +4,376 −0 vendor/plugins/blue-ridge/lib/jquery-1.3.2.js
  23. +29 −0 vendor/plugins/blue-ridge/lib/jquery.fn.js
  24. +109 −0 vendor/plugins/blue-ridge/lib/jquery.print.js
  25. BIN  vendor/plugins/blue-ridge/lib/js.jar
  26. +92 −0 vendor/plugins/blue-ridge/lib/screw.behaviors.js
  27. +82 −0 vendor/plugins/blue-ridge/lib/screw.builder.js
  28. +45 −0 vendor/plugins/blue-ridge/lib/screw.events.js
  29. +187 −0 vendor/plugins/blue-ridge/lib/screw.matchers.js
  30. +22 −0 vendor/plugins/blue-ridge/lib/screw.mocking.js
  31. +26 −0 vendor/plugins/blue-ridge/lib/shell.js
  32. +6 −0 vendor/plugins/blue-ridge/lib/smoke.core.js
  33. +130 −0 vendor/plugins/blue-ridge/lib/smoke.mock.js
  34. +29 −0 vendor/plugins/blue-ridge/lib/smoke.stub.js
  35. +50 −0 vendor/plugins/blue-ridge/lib/test_runner.js
  36. +62 −0 vendor/plugins/blue-ridge/tasks/javascript_testing_tasks.rake
View
15 test/javascript/application_spec.js
@@ -0,0 +1,15 @@
+require("spec_helper.js");
+require("../../public/javascripts/application.js");
+
+Screw.Unit(function(){
+ describe("Your application javascript", function(){
+ it("does something", function(){
+ expect("hello").to(equal, "hello");
+ });
+
+ it("accesses the DOM from fixtures/application.html", function(){
+ expect($('.select_me').length).to(equal, 2);
+ });
+ });
+});
+
View
16 test/javascript/fixtures/application.html
@@ -0,0 +1,16 @@
+<!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>Application | JavaScript Testing Results</title>
+ <link rel="stylesheet" href="screw.css" type="text/css" charset="utf-8" />
+ <script type="text/javascript" src="../../../vendor/plugins/blue-ridge/lib/blue-ridge.js"></script>
+</head>
+
+<body>
+ <!-- Put any HTML fixture elements here. -->
+ <div class="select_me"/>
+ <span class="select_me"/>
+ <div class="dont_select_me"/>
+</body>
+</html>
View
90 test/javascript/fixtures/screw.css
@@ -0,0 +1,90 @@
+html {
+ padding: 0.5em;
+ font-family: Georgia, serif;
+ background: #EDEBD5;
+}
+
+ li {
+ list-style-type: none;
+ }
+
+ .focused {
+ background-color: #F4F2E4;
+ }
+
+ .focused * {
+ opacity: 1.0;
+ }
+
+ h1, h2, p {
+ opacity: 0.4;
+ }
+
+ .describes {
+ padding-left: 0;
+ }
+
+ .describes h1 {
+ font-size: 1.1em;
+ color: #877C21;
+ line-height: 1.8em;
+ margin: 0pt 0pt 0.6em;
+ border-bottom: 1px solid transparent;
+ }
+
+ .describes h1:hover {
+ cursor: pointer;
+ color: #000;
+ background-color: #F4F2E4;
+ border-bottom: 1px solid #9A8E51;
+ }
+
+ .describes .describe {
+ margin-left: 0.6em;
+ padding-left: 0.6em;
+ border: 1px dashed #999;
+ }
+
+ .describes .describe .its {}
+
+ .describes .describe .its .it {
+ list-style-type: lower-roman;
+ list-style-position: outside;
+ }
+
+ .describes .describe .its .it h2 {
+ font-weight: normal;
+ font-style: italic;
+ padding-left: 0.5em;
+ font-size: 1.0em;
+ color: #877C21;
+ line-height: 1.8em;
+ margin: 0 0 0.5em;
+ border-bottom: 1px solid transparent;
+ }
+
+ .describes .describe .its .it.enqueued h2 {
+ background-color: #CC6600;
+ color: white !important;
+ }
+
+ .describes .describe .its .it.passed h2 {
+ background-color: #5A753D;
+ color: white !important;
+ }
+
+ .describes .describe .its .it.failed h2 {
+ background-color: #993300;
+ color: white !important;
+ }
+
+ .describes .describe .its .it.failed p {
+ margin-left: 1em;
+ color: #993300;
+ }
+
+ .describes .describe .its .it h2:hover {
+ cursor: pointer;
+ color: #000 !important;
+ border-bottom: 1px solid #9A8E51;
+ }
View
1  test/javascript/spec_helper.js
@@ -0,0 +1 @@
+// Use this file to require common dependencies or to setup useful test functions.
View
20 vendor/plugins/blue-ridge/LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2008-2009 Relevance, Inc.
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
22 vendor/plugins/blue-ridge/LICENSE-Screw.Unit
@@ -0,0 +1,22 @@
+Copyright (c) 2008 Nick Kallen
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
View
22 vendor/plugins/blue-ridge/LICENSE-Smoke
@@ -0,0 +1,22 @@
+Copyright (c) 2008 Andy Kent
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
View
233 vendor/plugins/blue-ridge/README.markdown
@@ -0,0 +1,233 @@
+Blue Ridge JavaScript Testing Rails Plugin
+==========================================
+
+The Blue Ridge JavaScript Testing Rails Plugin adds support for command-line and in-browser JavaScript unit tests to your Rails app. It bundles several great tools together in a convention-over-configuration, Rails-like way. These tools include:
+
+* `Rhino` - a Java-based JavaScript interpreter
+* `Screw.Unit` - a behaviour-driven development syntax for JavaScript similar to RSpec
+* `Smoke` - a JavaScript mocking & stubbing library similar to Mocha
+* `env.js` - a DOM implementation written entirely in JavaScript
+
+Installing and Running
+----------------------
+
+To install:
+
+ ./script/plugin install git://github.com/relevance/blue-ridge.git
+ ./script/generate blue_ridge
+
+To run all of the specs:
+
+ rake test:javascripts
+
+(Hint: You can also use the `spec:javascripts` or `examples:javascripts` aliases.)
+
+To run an individual spec file called "application_spec.js":
+
+ rake test:javascripts TEST=application
+
+To generate and run a spec for a JavaScript file called "public/javascripts/graphics.js" run:
+
+ ./script/generate javascript_spec graphics
+ rake test:javascripts TEST=graphics
+
+To run your spec inside a web browser, load the `HTML fixture` associated with the spec. (See below for more information on HTML fixtures and in-browser testing).
+
+Directory Layout: Specs and Fixtures
+-------------------------------------
+
+### JavaScript Spec Directories
+
+Blue Ridge creates a directory for your JavaScript specs in one of the following directories, depending on which tool you use to test your Ruby code:
+
+* examples/javascripts: if you're using [Micronaut](http://github.com/spicycode/micronaut)
+* spec/javascripts: if you're using [RSpec](http://rspec.info/)
+* test/javascript: if you're using anything else
+
+The layout of the JavaScript spec directories looks like this (assuming you created a "graphics" spec as described in the section above):
+
+#### "javascripts" directory
+* application_spec.js: file with Screw.Unit specs; intended for testing code in public/javascripts/application.js
+* graphics_spec.js: another spec file; intended for testing code in public/javascripts/graphics.js
+* spec_helper.js: a place a you to store your common configuration & convenience functions; auto-included by each spec
+
+#### "javascripts/fixtures" directory
+* application.html: base DOM for application_spec.js; also runs specs in-browser
+* graphics.html: base DOM for graphics_spec.js; also runs specs in-browser
+* screw.css: stylesheet for Screw.Unit output when running specs in-browser
+
+### Why We Need Fixtures
+Blue Ridge relies on the convention that each spec file will have a similarly named HTML file in the `fixtures` directory. We create one fixture per spec file so that env.js has a base DOM to emulate when running specs from the command line and so that we have an HTML launch-pad to run our specs in-browser.
+
+If you want to have specific HTML for a suite of specs, put it in the HTML fixture for that suite. If you want to run a specific suite of tests in Firefox or Internet Explorer, open the HTML fixture file with the same name and Screw.Unit automatically runs the specs associated with the fixture.
+
+Example Using jQuery
+---------------------------------------
+
+Blue Ridge is opinionated and assumes you're using jQuery by default. The plugin itself actually uses jQuery under the covers to run Screw.Unit.
+
+ require("spec_helper.js");
+ require("../../public/javascripts/application.js");
+
+ Screw.Unit(function() {
+ describe("Your application javascript", function() {
+ it("does something", function() {
+ expect("hello").to(equal, "hello");
+ });
+
+ it("accesses the DOM from fixtures/application.html", function() {
+ expect($('.select_me').length).to(equal, 2);
+ });
+ });
+ });
+
+(By the way, we don’t actually encourage you to write specs and tests for standard libraries like JQuery and Prototype. It just makes for an easy demo.)
+
+Example Using Prototype
+-----------------------
+
+It's very easy to add support for Prototype. Here's an example spec:
+
+ jQuery.noConflict();
+
+ require("spec_helper.js");
+ require("../../public/javascripts/prototype.js", {onload: function() {
+ require("../../public/javascripts/application.js");
+ }});
+
+ Screw.Unit(function() {
+ describe("Your application javascript", function() {
+ it("does something", function() {
+ expect("hello").to(equal, "hello");
+ });
+
+ it("accesses the DOM from fixtures/application.html", function() {
+ expect($$('.select_me').length).to(equal, 2);
+ });
+ });
+ });
+
+Note that you must do the following:
+
+* put jQuery into "no conflict" mode to give the `$` function back to Prototype
+* require the `prototype.js` file
+* chain any files that are dependent on `prototype.js` in the `onload` callback
+
+More Examples
+-------------
+
+To see Blue Ridge in action inside a working Rails app, check out the [Blue Ridge sample application](http://github.com/relevance/blue-ridge-sample-app). Among other things, this sample app includes examples of:
+
+* using nested `describe` functions
+* setting up per-spec HTML "fixtures"
+* stubbing functions
+* mocking functions
+* running the Blue Ridge specs as part of your default Rake task
+
+JavaScript API
+--------------
+
+The Blue Ridge plugin provides a handful of functions that help you write specs that run correctly inside a web browser as well from the Rhino command-line test runner.
+
+### require(fileName, [{onload:function}])
+When running from the command line, `require` becomes a Rhino call to `load`. In a web browser, `require` dynamically creates a JavaScript `script` tag and loads the given file for you. It takes an optional `onload` callback function that runs immediately after the given JavaScript file is loaded. This helps you chain dependencies. This is especially useful when running in-browser where each JavaScript file is loaded asynchronously in a separate thread.
+
+ require("../../public/javascripts/prerequisite.js", {onload: function() {
+ require("../../public/javascripts/dependent_file1.js");
+ require("../../public/javascripts/dependent_file2.js");
+ }});
+
+### debug(message)
+When running from the command line, `debug` simply prints a message to stdout, but in a web browser it outputs into the DOM directly. This helps you avoid using the `print` function which prints to stdout in Rhino but actually opens a file print dialog when running in a browser!
+
+### console.debug(message)
+If you use Firebug, you might add a `console.debug` function call in your tests to debug a problem. Calling this from the command-line would crash, however, because Firebug is missing. To make life a little easier, this `console.debug` function is just an alias to Rhino's `print` function and will write your message to stdout.
+
+Extras
+-------------
+
+### rake js:fixtures
+If you're on Mac OS X, this command opens your JavaScript fixtures directory using Finder so you can quickly locate and open any spec that you want to run in the browser. If you're running on Linux, it opens the fixtures directory using Firefox.
+
+### rake js:shell
+Runs an IRB-like JavaScript shell for debugging your JavaScript code. jQuery and env.js are pre-loaded for you to make debugging DOM code easy.
+
+ rake js:shell
+
+ =================================================
+ Rhino JavaScript Shell
+ To exit type 'exit', 'quit', or 'quit()'.
+ =================================================
+ - loaded env.js
+ - sample DOM loaded
+ - jQuery-1.2.6 loaded
+ =================================================
+ Rhino 1.7 release 2 PRERELEASE 2008 07 28
+ js> print("Hello World!")
+ Hello World!
+ js>
+
+Note that if you have `rlwrap` installed and on the command line path (and you really, really should!), then command-line history and readline arrow-up and down will be properly supported automatically. (You can get `rlwrap` from your friendly neighborhood package manager.)
+
+Mocking Example with Smoke
+--------------------------
+Smoke is a JavaScript mocking and stubbing toolkit that is somewhat similar to FlexMock or Mocha. It is automatically wired-in to undo its mocking after each Screw.Unit `it` block. Here's an example.
+
+ it("calculates the total cost of a contract by adding the prices of each component", function() {
+ var componentX = {}, componentY = {};
+ mock(SalesContract).should_receive("calculateComponentPrice").with_arguments(componentX).exactly(1, "times").and_return(42);
+ mock(SalesContract).should_receive("calculateComponentPrice").with_arguments(componentY).exactly(1, "times").and_return(24);
+ expect(SalesContract.calculateTotalCost([componentX, componentY])).to(equal, 66);
+ });
+
+TextMate Integration
+--------------------
+Run your specs directory from TextMate using the [Blue Ridge TextMate Bundle](http://github.com/karnowski/blue-ridge-tmbundle). (It's a fork of the original [Screw.Unit TextMate Bundle](http://github.com/coreyti/screw-unit-tmbundle) but adapted for use with the Blue Ridge plugin.)
+
+ cd ~/Library/Application Support/TextMate/Bundles/
+ git clone git://github.com/karnowski/blue-ridge-tmbundle.git Blue\ Ridge.tmbundle
+
+Then when editing a Screw.Unit spec file in TextMate you can:
+* press command-R to run the spec directly from TextMate
+* type snippets like "it", "des", "bef", "aft" and then press the tab key to expand into full it blocks, describe blocks, etc.
+
+Tips & Tricks
+-------------
+* Avoid using `print` in your tests while debugging. It works fine from the command line but causes lots of headaches in browser. (Just imagine a print dialog opening ten or fifteen times and then Firefox crashing. This is a mistake I've made too many times! Trust me!)
+* We don't recommend testing jQuery or Prototype, especially event wiring. (You don't test Rails, do you?) Instead write a separate function, test it, and wire it to events using jQuery or Prototype.
+
+Bugs & Patches
+--------------
+First, if you see any bugs or possible improvements, please use the project's [GitHub issue tracker](http://github.com/relevance/blue-ridge/issues) to let us know about them.
+
+But even better, fork our [GitHub repo](http://www.github.com/relevance/blue-ridge) and start hacking! If you have patches, send us pull requests. Also, [env.js](http://github.com/thatcher/env-js), [Smoke](http://github.com/andykent/smoke), and [Screw.Unit](http://github.com/nkallen/screw-unit) could use your love too!
+
+Links
+-------------
+* [Blue Ridge JavaScript Testing Rails Plugin](http://github.com/relevance/blue-ridge)
+* [Blue Ridge Sample App](http://github.com/relevance/blue-ridge-sample-app)
+* [Justin Gehtland's "Fully Headless JSSpec" Blog Post](http://blog.thinkrelevance.com/2008/7/31/fully-headless-jsspec)
+* [Screw.Unit](http://github.com/nkallen/screw-unit)
+* [Screw.Unit Mailing List](http://groups.google.com/group/screw-unit)
+* [Smoke](http://github.com/andykent/smoke)
+* [env.js](http://github.com/thatcher/env-js)
+* [env.js Mailing List](http://groups.google.com/group/envjs)
+* [Mozilla Rhino](http://www.mozilla.org/rhino/)
+* [W3C DOM Specifications](http://www.w3.org/DOM/DOMTR)
+
+Contributors
+------------
+* Justin Gehtland
+* Geof Dagley
+* Larry Karnowski
+* Chris Thatcher (for numerous env.js bug fixes!)
+* Raimonds Simanovskis
+* Jason Rudolph
+
+Copyrights
+------------
+* Copyright &copy; 2008-2009 [Relevance, Inc.](http://www.thinkrelevance.com/), under the MIT license
+* env.js - Copyright 2007-2009 John Resig, under the MIT License
+* Screw.Unit - Copyright 2008 Nick Kallen, license attached
+* Rhino - Copyright 2009 Mozilla Foundation, GPL 2.0
+* Smoke - Copyright 2008 Andy Kent, license attached
View
42 vendor/plugins/blue-ridge/TODO.taskpaper
@@ -0,0 +1,42 @@
+Release 1:
+- cleanup README
+ - include correct copyright notices of vendored software @done
+ - add API documentation (require, etc) @done
+ - explain that we're jQuery-opinionated, but give jQuery.noConflict() example for Prototype @done
+ - list Java (version?) as a system requirement
+- improve test output for command line @done(2009-01-30)
+- merge back to Relevance's javascript_testing project on GitHub @done
+- change generators to use Screw.Unit style instead of JS-Spec @done
+- test that env-js works with DOCTYPEs now? @done(2009-01-30)
+- rake task to open fixtures in your favorite web browser? @done
+- make the generator check for "test", "spec", and then "examples" directory to create the "javascript" dir @done(2009-04-11)
+- support Prototype @done
+- support jQuery 1.3.x @env.js @done(2009-05-08)
+ - in browser @done(2009-04-11)
+ - from command line @done(2009-05-08)
+- when clicking on a describe or it block in browser, run focused tests (thanks rsim!) @done(2009-04-11)
+- fix timing issues of "require" calls in browser tests often causing first test to fail @done(2009-04-11)
+- include Smoke for mocking @done(2009-04-11)
+ - automatically require @done(2009-04-11)
+ - command line @done(2009-04-11)
+ - browser @done(2009-04-11)
+ - add examples of mocking to README @done
+ - improve mocking example in README - show code under test
+ - caveat re stubbing in README
+- change name of plugin @done
+ - change the relevance github fork's name @done
+ - create a "javascript_testing" github project with a README that points folks to the new name @done
+ - what is the new name? --> "blue-ridge" @done
+Release 2:
+- Document TextMate support
+ - fork the screw.unit text mate bundle
+ - add the TextMate runner from the karnowski/javascript_testing Textmate bundle
+ - "git clone git://github.com/coreyti/screw-unit-tmbundle.git screw-unit.tmbundle"
+ - have to remove the "run" macro there
+ - "git clone git://github.com/karnowski/javascript-testing-tmbundle.git javascript-testing.tmbundle"
+ - needs to be smart enough to look for spec, test, or examples -- right now hard-coded to "test"
+ - known text-mate issue with builder.rb: http://robsanheim.com/2007/12/07/fixing-textmate-test-issues-blank_slate_method_added-stack-level-too-deep-systemstackerror/
+ - might also have to move it in the "Pristine Copy" version too
+- sprockets support?
+- improve "require" to take an array and chain them together in order
+- handle display of nested describes better for command-line
View
18 vendor/plugins/blue-ridge/generators/blue_ridge/blue_ridge_generator.rb
@@ -0,0 +1,18 @@
+class BlueRidgeGenerator < Rails::Generator::Base
+ def manifest
+ record do |m|
+ m.directory base_dir
+ m.file 'application_spec.js', "#{base_dir}/application_spec.js"
+ m.file 'spec_helper.js', "#{base_dir}/spec_helper.js"
+
+ m.directory "#{base_dir}/fixtures"
+ m.file 'application.html', "#{base_dir}/fixtures/application.html"
+ m.file 'screw.css', "#{base_dir}/fixtures/screw.css"
+ end
+ end
+
+ def base_dir
+ @base_dir ||= File.exist?("examples") ? "examples/javascripts" : File.exist?("spec") ? "spec/javascripts" : "test/javascript"
+ end
+
+end
View
16 vendor/plugins/blue-ridge/generators/blue_ridge/templates/application.html
@@ -0,0 +1,16 @@
+<!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>Application | JavaScript Testing Results</title>
+ <link rel="stylesheet" href="screw.css" type="text/css" charset="utf-8" />
+ <script type="text/javascript" src="../../../vendor/plugins/blue-ridge/lib/blue-ridge.js"></script>
+</head>
+
+<body>
+ <!-- Put any HTML fixture elements here. -->
+ <div class="select_me"/>
+ <span class="select_me"/>
+ <div class="dont_select_me"/>
+</body>
+</html>
View
15 vendor/plugins/blue-ridge/generators/blue_ridge/templates/application_spec.js
@@ -0,0 +1,15 @@
+require("spec_helper.js");
+require("../../public/javascripts/application.js");
+
+Screw.Unit(function(){
+ describe("Your application javascript", function(){
+ it("does something", function(){
+ expect("hello").to(equal, "hello");
+ });
+
+ it("accesses the DOM from fixtures/application.html", function(){
+ expect($('.select_me').length).to(equal, 2);
+ });
+ });
+});
+
View
90 vendor/plugins/blue-ridge/generators/blue_ridge/templates/screw.css
@@ -0,0 +1,90 @@
+html {
+ padding: 0.5em;
+ font-family: Georgia, serif;
+ background: #EDEBD5;
+}
+
+ li {
+ list-style-type: none;
+ }
+
+ .focused {
+ background-color: #F4F2E4;
+ }
+
+ .focused * {
+ opacity: 1.0;
+ }
+
+ h1, h2, p {
+ opacity: 0.4;
+ }
+
+ .describes {
+ padding-left: 0;
+ }
+
+ .describes h1 {
+ font-size: 1.1em;
+ color: #877C21;
+ line-height: 1.8em;
+ margin: 0pt 0pt 0.6em;
+ border-bottom: 1px solid transparent;
+ }
+
+ .describes h1:hover {
+ cursor: pointer;
+ color: #000;
+ background-color: #F4F2E4;
+ border-bottom: 1px solid #9A8E51;
+ }
+
+ .describes .describe {
+ margin-left: 0.6em;
+ padding-left: 0.6em;
+ border: 1px dashed #999;
+ }
+
+ .describes .describe .its {}
+
+ .describes .describe .its .it {
+ list-style-type: lower-roman;
+ list-style-position: outside;
+ }
+
+ .describes .describe .its .it h2 {
+ font-weight: normal;
+ font-style: italic;
+ padding-left: 0.5em;
+ font-size: 1.0em;
+ color: #877C21;
+ line-height: 1.8em;
+ margin: 0 0 0.5em;
+ border-bottom: 1px solid transparent;
+ }
+
+ .describes .describe .its .it.enqueued h2 {
+ background-color: #CC6600;
+ color: white !important;
+ }
+
+ .describes .describe .its .it.passed h2 {
+ background-color: #5A753D;
+ color: white !important;
+ }
+
+ .describes .describe .its .it.failed h2 {
+ background-color: #993300;
+ color: white !important;
+ }
+
+ .describes .describe .its .it.failed p {
+ margin-left: 1em;
+ color: #993300;
+ }
+
+ .describes .describe .its .it h2:hover {
+ cursor: pointer;
+ color: #000 !important;
+ border-bottom: 1px solid #9A8E51;
+ }
View
1  vendor/plugins/blue-ridge/generators/blue_ridge/templates/spec_helper.js
@@ -0,0 +1 @@
+// Use this file to require common dependencies or to setup useful test functions.
View
30 vendor/plugins/blue-ridge/generators/javascript_spec/javascript_spec_generator.rb
@@ -0,0 +1,30 @@
+class JavascriptSpecGenerator < Rails::Generator::NamedBase
+ def manifest
+ file_path_with_spec, file_path_without_spec = file_path_with_and_without_spec
+
+ record do |m|
+ m.directory base_dir
+ m.directory "#{base_dir}/fixtures"
+
+ options = {:class_name_without_spec => class_name_without_spec, :file_path_without_spec => file_path_without_spec}
+ m.template 'javascript_spec.js.erb', "#{base_dir}/#{file_path_with_spec}.js", :assigns => options
+ m.template 'fixture.html.erb', "#{base_dir}/fixtures/#{file_path_without_spec}.html", :assigns => options
+ end
+ end
+
+ def base_dir
+ @base_dir ||= File.exist?("spec") ? "spec/javascripts" : "test/javascript"
+ end
+
+ def file_path_with_and_without_spec
+ if (file_path =~ /_spec$/i)
+ [file_path, file_path.gsub(/_spec$/, "")]
+ else
+ [file_path + "_spec", file_path]
+ end
+ end
+
+ def class_name_without_spec
+ (class_name =~ /Spec$/) ? class_name.gsub(/Spec$/, "") : class_name
+ end
+end
View
13 vendor/plugins/blue-ridge/generators/javascript_spec/templates/fixture.html.erb
@@ -0,0 +1,13 @@
+<!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><%= class_name_without_spec %> | JavaScript Testing Results</title>
+ <link rel="stylesheet" href="screw.css" type="text/css" charset="utf-8" />
+ <script type="text/javascript" src="../../../vendor/plugins/blue-ridge/lib/blue-ridge.js"></script>
+</head>
+
+<body>
+ <!-- Put any HTML fixture elements here. -->
+</body>
+</html>
View
10 vendor/plugins/blue-ridge/generators/javascript_spec/templates/javascript_spec.js.erb
@@ -0,0 +1,10 @@
+require("spec_helper.js");
+require("../../public/javascripts/<%= file_path_without_spec %>.js");
+
+Screw.Unit(function(){
+ describe("<%= class_name_without_spec %>", function(){
+ it("does something", function(){
+ expect("hello").to(equal, "hello");
+ });
+ });
+});
View
43 vendor/plugins/blue-ridge/lib/blue-ridge.js
@@ -0,0 +1,43 @@
+function require(url, options) {
+ //this function expects to be ran from the context of the spec/javascripts/fixtures or test/javascript/fixtures
+ //directory, so add a '../' prefix to all Javascript paths
+ url = "../" + url;
+
+ var head = document.getElementsByTagName("head")[0];
+ var script = document.createElement("script");
+ script.src = url;
+
+ options = options || {};
+
+ if (options['onload']) {
+ // Attach handlers for all browsers
+ script.onload = script.onreadystatechange = options['onload'];
+ }
+
+ head.appendChild(script);
+}
+
+function debug(message) {
+ document.writeln(message + " <br/>");
+}
+
+function derive_spec_name_from_current_file() {
+ var file_prefix = new String(window.location).match(/.*\/(.*?)\.html/)[1];
+ 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");
+
+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(derive_spec_name_from_current_file());
View
32 vendor/plugins/blue-ridge/lib/consoleReportForRake.js
@@ -0,0 +1,32 @@
+(function($) {
+ $(Screw).bind("before", function(){
+ function example_name(element){
+ // TODO: handle nested describes!
+ var context_name = $(element).parents(".describe").children("h1").text();
+ var example_name = $(element).children("h2").text();
+
+ return context_name + " - " + example_name;
+ }
+
+ $('.it')
+ .bind('passed', function(){
+ java.lang.System.out.print(".");
+ })
+ .bind('failed', function(e, reason){
+ print("\nFAILED: " + example_name(this));
+ print(" " + reason + "\n");
+ });
+ });
+
+ $(Screw).bind("after", function(){
+ var testCount = $('.passed').length + $('.failed').length;
+ var failures = $('.failed').length;
+ var elapsedTime = ((new Date() - Screw.suite_start_time)/1000.0);
+
+ print("\n")
+ print(testCount + ' test(s), ' + failures + ' failure(s)');
+ print(elapsedTime.toString() + " seconds elapsed");
+
+ if(failures > 0) { java.lang.System.exit(1) };
+ });
+})(jQuery);
View
8,841 vendor/plugins/blue-ridge/lib/env.rhino.js
8,841 additions, 0 deletions not shown
View
3,549 vendor/plugins/blue-ridge/lib/jquery-1.2.6.js
3,549 additions, 0 deletions not shown
View
4,376 vendor/plugins/blue-ridge/lib/jquery-1.3.2.js
4,376 additions, 0 deletions not shown
View
29 vendor/plugins/blue-ridge/lib/jquery.fn.js
@@ -0,0 +1,29 @@
+(function($) {
+ $.fn.fn = function() {
+ var self = this;
+ var extension = arguments[0], name = arguments[0];
+ if (typeof name == "string") {
+ return apply(self, name, $.makeArray(arguments).slice(1, arguments.length));
+ } else {
+ $.each(extension, function(key, value) {
+ define(self, key, value);
+ });
+ return self;
+ }
+ }
+ function define(self, name, fn) {
+ self.data(namespacedName(name), fn);
+ };
+ function apply(self, name, args) {
+ var result;
+ self.each(function(i, item) {
+ var fn = $(item).data(namespacedName(name));
+ if (fn) result = fn.apply(item, args)
+ else throw(name + " is not defined");
+ });
+ return result;
+ };
+ function namespacedName(name) {
+ return 'fn.' + name;
+ }
+})(jQuery);
View
109 vendor/plugins/blue-ridge/lib/jquery.print.js
@@ -0,0 +1,109 @@
+(function($) {
+
+ function print_array(obj, opts) {
+ var result = [];
+ for (var i = 0; i < Math.min(opts.max_array, obj.length); i++)
+ result.push($.print(obj[i], $.extend({}, opts, { max_array: 3, max_string: 40 })));
+
+ if (obj.length > opts.max_array)
+ result.push((obj.length - opts.max_array) + ' more...');
+ if (result.length == 0) return "[]"
+ return "[ " + result.join(", ") + " ]";
+ }
+
+ function print_element(obj) {
+ if (obj.nodeType == 1) {
+ var result = [];
+ var properties = [ 'className', 'id' ];
+ var extra = {
+ 'input': ['type', 'name', 'value'],
+ 'a': ['href', 'target'],
+ 'form': ['method', 'action'],
+ 'script': ['src'],
+ 'link': ['href'],
+ 'img': ['src']
+ };
+
+ $.each(properties.concat(extra[obj.tagName.toLowerCase()] || []), function(){
+ if (obj[this])
+ result.push(' ' + this.replace('className', 'class') + "=" + $.print(obj[this]))
+ });
+ return "<" + obj.tagName.toLowerCase()
+ + result.join('') + ">";
+ }
+ }
+
+ function print_object(obj, opts) {
+ var seen = opts.seen || [ obj ];
+
+ var result = [], key, value;
+ for (var k in obj) {
+ if (obj.hasOwnProperty(k) && $.inArray(obj[k], seen) < 0) {
+ seen.push(obj[k]);
+ value = $.print(obj[k], $.extend({}, opts, { max_array: 6, max_string: 40, seen: seen }));
+ } else
+ value = "...";
+ result.push(k + ": " + value);
+ }
+ if (result.length == 0) return "{}";
+ return "{ " + result.join(", ") + " }";
+ }
+
+ function print_string(value, opts) {
+ var character_substitutions = {
+ '\b': '\\b',
+ '\t': '\\t',
+ '\n': '\\n',
+ '\f': '\\f',
+ '\r': '\\r',
+ '"' : '\\"',
+ '\\': '\\\\'
+ };
+ var r = /["\\\x00-\x1f\x7f-\x9f]/g;
+
+ var str = r.test(value)
+ ? '"' + value.replace(r, function (a) {
+ var c = character_substitutions[a];
+ if (c) return c;
+ c = a.charCodeAt();
+ return '\\u00' + Math.floor(c / 16).toString(16) + (c % 16).toString(16);
+ }) + '"'
+ : '"' + value + '"';
+ if (str.length > opts.max_string)
+ return str.slice(0, opts.max_string + 1) + '..."';
+ else
+ return str;
+ }
+
+ $.print = function(obj, options) {
+ var opts = $.extend({}, { max_array: 10, max_string: 100 }, options);
+
+ if (typeof obj == 'undefined')
+ return "undefined";
+ else if (typeof obj == 'boolean')
+ return obj.toString();
+ else if (typeof obj == 'number')
+ return obj.toString();
+ else if (!obj)
+ return "null";
+ else if (typeof obj == 'string')
+ return print_string(obj, opts);
+ else if (obj instanceof RegExp)
+ return obj.toString();
+ else if (obj instanceof Array || obj.callee || obj.item)
+ return print_array(obj, opts);
+ else if (typeof obj == 'function' || obj instanceof Function)
+ return obj.toString().match(/^([^)]*\))/)[1];
+ else if (obj.nodeType)
+ return print_element(obj);
+ else if (obj instanceof jQuery)
+ return "$(" + $.print(obj.get()) + ")";
+ else if (obj instanceof Error)
+ return print_object(obj, $.extend({}, options, { max_string: 200 }));
+ else if (obj instanceof Object)
+ return print_object(obj, opts);
+ else
+ return obj.toString().replace(/\n\s*/g, '');
+ }
+
+})(jQuery);
View
BIN  vendor/plugins/blue-ridge/lib/js.jar
Binary file not shown
View
92 vendor/plugins/blue-ridge/lib/screw.behaviors.js
@@ -0,0 +1,92 @@
+(function($) {
+ $(Screw).bind('loaded', function() {
+ $('.status').fn({
+ display: function() {
+ $(this).html(
+ $('.passed').length + $('.failed').length + ' test(s), ' + $('.failed').length + ' failure(s)<br />' +
+ ((new Date() - Screw.suite_start_time)/1000.0).toString() + " seconds elapsed"
+ );
+ }
+ });
+
+ $('.describe').fn({
+ parent: function() {
+ return $(this).parent('.describes').parent('.describe');
+ },
+
+ run_befores: function() {
+ $(this).fn('parent').fn('run_befores');
+ $(this).children('.befores').children('.before').fn('run');
+ },
+
+ run_afters: function() {
+ $(this).fn('parent').fn('run_afters');
+ $(this).children('.afters').children('.after').fn('run');
+ },
+
+ enqueue: function() {
+ $(this).children('.its').children('.it').fn('enqueue');
+ $(this).children('.describes').children('.describe').fn('enqueue');
+ },
+
+ selector: function() {
+ return $(this).fn('parent').fn('selector')
+ + ' > .describes > .describe:eq(' + $(this).parent('.describes').children('.describe').index(this) + ')';
+ }
+ });
+
+ $('body > .describe').fn({
+ selector: function() { return 'body > .describe' }
+ });
+
+ $('.it').fn({
+ parent: function() {
+ return $(this).parent('.its').parent('.describe');
+ },
+
+ run: function() {
+ try {
+ try {
+ $(this).fn('parent').fn('run_befores');
+ $(this).data('screwunit.run')();
+ } finally {
+ $(this).fn('parent').fn('run_afters');
+ }
+ $(this).trigger('passed');
+ } catch(e) {
+ $(this).trigger('failed', [e]);
+ }
+ },
+
+ enqueue: function() {
+ var self = $(this).trigger('enqueued');
+ $(Screw)
+ .queue(function() {
+ self.fn('run');
+ setTimeout(function() { $(Screw).dequeue() }, 0);
+ });
+ },
+
+ selector: function() {
+ return $(this).fn('parent').fn('selector')
+ + ' > .its > .it:eq(' + $(this).parent('.its').children('.it').index(this) + ')';
+ }
+ });
+
+ $('.before').fn({
+ run: function() { $(this).data('screwunit.run')() }
+ });
+
+ $('.after').fn({
+ run: function() { $(this).data('screwunit.run')() }
+ });
+
+ $(Screw).trigger('before');
+ var to_run = unescape(location.search.slice(1)) || 'body > .describe > .describes > .describe';
+ $(to_run)
+ .focus()
+ .eq(0).trigger('scroll').end()
+ .fn('enqueue');
+ $(Screw).queue(function() { $(Screw).trigger('after') });
+ })
+})(jQuery);
View
82 vendor/plugins/blue-ridge/lib/screw.builder.js
@@ -0,0 +1,82 @@
+var Screw = (function($) {
+ var screw = {
+ Unit: function(fn) {
+ var contents = fn.toString().match(/^[^\{]*{((.*\n*)*)}/m)[1];
+ var fn = new Function("matchers", "specifications",
+ "with (specifications) { with (matchers) { " + contents + " } }"
+ );
+
+ $(Screw).queue(function() {
+ Screw.Specifications.context.push($('body > .describe'));
+ fn.call(this, Screw.Matchers, Screw.Specifications);
+ Screw.Specifications.context.pop();
+ $(this).dequeue();
+ });
+ },
+
+ Specifications: {
+ context: [],
+
+ describe: function(name, fn) {
+ var describe = $('<li class="describe"></li>')
+ .append($('<h1></h1>').text(name))
+ .append('<ol class="befores"></ol>')
+ .append('<ul class="its"></ul>')
+ .append('<ul class="describes"></ul>')
+ .append('<ol class="afters"></ol>');
+
+ this.context.push(describe);
+ fn.call();
+ this.context.pop();
+
+ this.context[this.context.length-1]
+ .children('.describes')
+ .append(describe);
+ },
+
+ it: function(name, fn) {
+ var it = $('<li class="it"></li>')
+ .append($('<h2></h2>').text(name))
+ .data('screwunit.run', fn);
+
+ this.context[this.context.length-1]
+ .children('.its')
+ .append(it);
+ },
+
+ before: function(fn) {
+ var before = $('<li class="before"></li>')
+ .data('screwunit.run', fn);
+
+ this.context[this.context.length-1]
+ .children('.befores')
+ .append(before);
+ },
+
+ after: function(fn) {
+ var after = $('<li class="after"></li>')
+ .data('screwunit.run', fn);
+
+ this.context[this.context.length-1]
+ .children('.afters')
+ .append(after);
+ }
+ }
+ };
+
+ $(screw).queue(function() { $(screw).trigger('loading') });
+
+ $(window).load(function(){
+ $('<div class="describe"></div>')
+ .append('<h3 class="status"></h3>')
+ .append('<ol class="befores"></ol>')
+ .append('<ul class="describes"></ul>')
+ .append('<ol class="afters"></ol>')
+ .appendTo('body');
+
+ $(screw).dequeue();
+ $(screw).trigger('loaded');
+ });
+
+ return screw;
+})(jQuery);
View
45 vendor/plugins/blue-ridge/lib/screw.events.js
@@ -0,0 +1,45 @@
+(function($) {
+ $(Screw)
+ .bind('loaded', function() {
+ $('.describe, .it')
+ .click(function() {
+ document.location = location.href.split('?')[0] + '?' + $(this).fn('selector');
+ return false;
+ })
+ .focus(function() {
+ return $(this).addClass('focused');
+ })
+ .bind('scroll', function() {
+ document.body.scrollTop = $(this).offset().top;
+ });
+
+ $('.it')
+ .bind('enqueued', function() {
+ $(this).addClass('enqueued');
+ })
+ .bind('running', function() {
+ $(this).addClass('running');
+ })
+ .bind('passed', function() {
+ $(this).addClass('passed');
+ })
+ .bind('failed', function(e, reason) {
+ $(this)
+ .addClass('failed')
+ .append($('<p class="error"></p>').text(reason.toString()));
+
+ var file = reason.fileName || reason.sourceURL;
+ var line = reason.lineNumber || reason.line;
+ if (file || line) {
+ $(this).append($('<p class="error"></p>').text('line ' + line + ', ' + file));
+ }
+ })
+ })
+ .bind('before', function() {
+ Screw.suite_start_time = new Date();
+ $('.status').text('Running...');
+ })
+ .bind('after', function() {
+ $('.status').fn('display')
+ })
+})(jQuery);
View
187 vendor/plugins/blue-ridge/lib/screw.matchers.js
@@ -0,0 +1,187 @@
+Screw.Matchers = (function($) {
+ return matchers = {
+ expect: function(actual) {
+ return {
+ to: function(matcher, expected, not) {
+ var matched = matcher.match(expected, actual);
+ if (not ? matched : !matched) {
+ throw(matcher.failure_message(expected, actual, not));
+ }
+ },
+
+ to_not: function(matcher, expected) {
+ this.to(matcher, expected, true);
+ }
+ }
+ },
+
+ equal: {
+ match: function(expected, actual) {
+ if(expected == actual) return true;
+ if(actual == undefined) return false;
+
+ if (expected instanceof Array) {
+ for (var i = 0; i < actual.length; i++)
+ if (!Screw.Matchers.equal.match(expected[i], actual[i])) return false;
+ return actual.length == expected.length;
+ } else if (expected instanceof Object) {
+ for (var key in expected)
+ if (!this.match(expected[key], actual[key])) return false;
+ for (var key in actual)
+ if (!this.match(actual[key], expected[key])) return false;
+ return true;
+ }
+ return false;
+ },
+
+ failure_message: function(expected, actual, not) {
+ return 'expected ' + $.print(actual) + (not ? ' to not equal ' : ' to equal ') + $.print(expected);
+ }
+ },
+
+ be_gt: {
+ match: function(expected, actual) {
+ return actual > expected;
+ },
+
+ failure_message: function(expected, actual, not) {
+ return 'expected ' + $.print(actual) + (not ? ' to not ' : ' to ') + 'be greater than ' + $.print(expected);
+ }
+ },
+
+ be_gte: {
+ match: function(expected, actual) {
+ return actual >= expected;
+ },
+
+ failure_message: function(expected, actual, not) {
+ return 'expected ' + $.print(actual) + (not ? ' to not ' : ' to ') + 'be greater than or equal to ' + $.print(expected);
+ }
+ },
+
+ be_lt: {
+ match: function(expected, actual) {
+ return actual < expected;
+ },
+
+ failure_message: function(expected, actual, not) {
+ return 'expected ' + $.print(actual) + (not ? ' to not ' : ' to ') + 'be less than ' + $.print(expected);
+ }
+ },
+
+ be_lte: {
+ match: function(expected, actual) {
+ return actual <= expected;
+ },
+
+ failure_message: function(expected, actual, not) {
+ return 'expected ' + $.print(actual) + (not ? ' to not ' : ' to ') + 'be less than or equal to ' + $.print(expected);
+ }
+ },
+
+ match: {
+ match: function(expected, actual) {
+ if (expected.constructor == RegExp)
+ return expected.exec(actual.toString());
+ else
+ return actual.indexOf(expected) > -1;
+ },
+
+ failure_message: function(expected, actual, not) {
+ return 'expected ' + $.print(actual) + (not ? ' to not match ' : ' to match ') + $.print(expected);
+ }
+ },
+
+ be_empty: {
+ match: function(expected, actual) {
+ if (actual.length == undefined) throw(actual.toString() + " does not respond to length");
+
+ return actual.length == 0;
+ },
+
+ failure_message: function(expected, actual, not) {
+ return 'expected ' + $.print(actual) + (not ? ' to not be empty' : ' to be empty');
+ }
+ },
+
+ have_length: {
+ match: function(expected, actual) {
+ if (actual.length == undefined) throw(actual.toString() + " does not respond to length");
+
+ return actual.length == expected;
+ },
+
+ failure_message: function(expected, actual, not) {
+ return 'expected ' + $.print(actual) + (not ? ' to not' : ' to') + ' have length ' + expected;
+ }
+ },
+
+ be_null: {
+ match: function(expected, actual) {
+ return actual == null;
+ },
+
+ failure_message: function(expected, actual, not) {
+ return 'expected ' + $.print(actual) + (not ? ' to not be null' : ' to be null');
+ }
+ },
+
+ be_undefined: {
+ match: function(expected, actual) {
+ return actual == undefined;
+ },
+
+ failure_message: function(expected, actual, not) {
+ return 'expected ' + $.print(actual) + (not ? ' to not be undefined' : ' to be undefined');
+ }
+ },
+
+ be_true: {
+ match: function(expected, actual) {
+ return actual;
+ },
+
+ failure_message: function(expected, actual, not) {
+ return 'expected ' + $.print(actual) + (not ? ' to not be true' : ' to be true');
+ }
+ },
+
+ be_false: {
+ match: function(expected, actual) {
+ return !actual;
+ },
+
+ failure_message: function(expected, actual, not) {
+ return 'expected ' + $.print(actual) + (not ? ' to not be false' : ' to be false');
+ }
+ },
+
+ match_selector: {
+ match: function(expected, actual) {
+ if (!(actual instanceof jQuery)) {
+ throw expected.toString() + " must be an instance of jQuery to match against a selector"
+ }
+
+ return actual.is(expected);
+ },
+
+ failure_message: function(expected, actual, not) {
+ return 'expected ' + $.print(actual) + (not ? ' to not match selector ' : ' to match selector ') + expected;
+ }
+ },
+
+ contain_selector: {
+ match: function(expected, actual) {
+ if (!(actual instanceof jQuery)) {
+ throw expected.toString() + " must be an instance of jQuery to match against a selector"
+ }
+
+ return actual.find(expected).length > 0;
+ },
+
+ failure_message: function(expected, actual, not) {
+ return 'expected ' + $.print(actual) + (not ? ' to not contain selector ' : ' to contain selector ') + expected;
+ }
+ }
+ }
+})(jQuery);
View
22 vendor/plugins/blue-ridge/lib/screw.mocking.js
@@ -0,0 +1,22 @@
+// This is a lightweight bridge between Smoke and Screw.Unit.
+// It shadows mocking and stubbing onto the matchers to make them available within tests.
+
+Screw.Matchers.mock = function(m) {
+ return Smoke.Mock(m);
+};
+
+Screw.Matchers.stub = function(obj, attr) {
+ return new Smoke.Stub(obj,attr);
+};
+
+(function($) {
+ $(Screw).bind("before", function(){
+ function checkAndResetSmoke() {
+ Smoke.checkExpectations();
+ Smoke.reset();
+ }
+
+ $('.it').bind('passed', function(){ checkAndResetSmoke() });
+ $('.it').bind('failed', function(){ checkAndResetSmoke() });
+ });
+})(jQuery);
View
26 vendor/plugins/blue-ridge/lib/shell.js
@@ -0,0 +1,26 @@
+(function(){
+ var _old_quit = this.quit;
+ this.__defineGetter__("exit", function(){ _old_quit() });
+ this.__defineGetter__("quit", function(){ _old_quit() });
+
+ print("=================================================");
+ print(" Rhino JavaScript Shell");
+ 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";
+
+ 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");
+
+ print("=================================================");
+})();
View
6 vendor/plugins/blue-ridge/lib/smoke.core.js
@@ -0,0 +1,6 @@
+Smoke = {
+ print: function(v) {
+ // use the jquery print plugin if it is available or fall back to toString();
+ return (jQuery && jQuery.print) ? $.print(v) : v.toString();
+ }
+};
View
130 vendor/plugins/blue-ridge/lib/smoke.mock.js
@@ -0,0 +1,130 @@
+// Overide these functions for custom pass/fail behaviours
+Smoke.passed = function(mock){
+ Smoke.passCount++;
+};
+
+Smoke.failed = function(mock, message){
+ Smoke.failCount++;
+ throw(message);
+};
+
+// Some helpers
+Smoke.reset = function(){
+ Smoke.mocks = [];
+ Smoke.passCount = 0;
+ Smoke.failCount = 0;
+};
+Smoke.reset();
+
+Smoke.checkExpectations = function(){
+ for(var i=0; i<Smoke.mocks.length; i++) Smoke.mocks[i].checkExpectations();
+};
+
+// Don't play beyond here unless you know what you're doing
+Smoke.Mock = function(originalObj) {
+ var obj = originalObj || {} ;
+ obj._expectations = {};
+ obj.stub = function(attr){
+ return new Smoke.Stub(this, attr);
+ },
+ obj.should_receive = function(attr){
+ var expectation = new Smoke.Mock.Expectation(this, attr);
+ if(this._expectations[attr]==undefined) this._expectations[attr] = [];
+ this._expectations[attr].push(expectation);
+ var previousFunction = this[attr];
+ var mock = this;
+ this[attr] = function() {
+ var result = expectation.run(arguments);
+ if(result!=undefined) return result;
+ return previousFunction!=undefined ? previousFunction.apply(mock,arguments) : undefined;
+ };
+ return expectation;
+ },
+ obj.checkExpectations = function(){
+ for(var e in this._expectations) {
+ var expectations = this._expectations[e]
+ for(var i in expectations) expectations[i].check();
+ };
+ },
+ Smoke.mocks.push(obj);
+ return obj;
+};
+
+Smoke.Mock.Expectation = function(mock, attr) {
+ this._mock = mock;
+ this._attr = attr;
+ this.callCount = 0;
+ this.returnValue = undefined;
+ this.callerArgs = [];
+};
+
+Smoke.Mock.Expectation.prototype = {
+ exactly: function(count,type){
+ // type isn't used for now, it's just syntax ;)
+ this.minCount = this.maxCount = undefined;
+ this.exactCount = this.parseCount(count);
+ return this;
+ },
+ at_most: function(count,type){
+ this.maxCount = this.parseCount(count);
+ return this;
+ },
+ at_least: function(count,type){
+ this.minCount = this.parseCount(count);
+ return this;
+ },
+ with_arguments: function(){
+ this.callerArgs = arguments;
+ return this
+ },
+ run: function(args){
+ if(this.compareArrays(args, this.callerArgs)) {
+ this.callCount+=1;
+ return this.returnValue;
+ };
+ },
+ and_return: function(v){
+ this.returnValue = v
+ },
+ check: function(){
+ if(this.exactCount!=undefined) this.checkExactCount();
+ if(this.minCount!=undefined) this.checkMinCount();
+ if(this.maxCount!=undefined) this.checkMaxCount();
+ },
+ checkExactCount: function(){
+ if(this.exactCount==this.callCount) Smoke.passed(this)//console.log('Mock passed!')
+ else Smoke.failed(this, 'expected '+this.methodSignature()+' to be called exactly '+this.exactCount+" times but it got called "+this.callCount+' times');
+ },
+ checkMinCount: function(){
+ if(this.minCount<=this.callCount) Smoke.passed(this);
+ else Smoke.failed(this, 'expected '+this.methodSignature()+' to be called at least '+this.minCount+" times but it only got called "+this.callCount+' times');
+ },
+ checkMaxCount: function(){
+ if(this.maxCount>=this.callCount) Smoke.passed(this);//console.log('Mock passed!')
+ else Smoke.failed(this, 'expected '+this.methodSignature()+' to be called at most '+this.maxCount+" times but it actually got called "+this.callCount+' times');
+ },
+ methodSignature: function(){
+ var a = '';
+ var args = this.callerArgs;
+ for(var i=0; i<args.length; i++) a += Smoke.print(args[i])+', ';
+ a =a.slice(0,-2);
+ return this._attr+'('+a+')'
+ },
+ parseCount: function(c){
+ switch(c){
+ case 'once' : c=1; break;
+ case 'twice' : c=2; break;
+ }
+ return c;
+ },
+ compareArrays: function(a,b) {
+ if (a.length != b.length) return false;
+ for (var i = 0; i < b.length; i++) {
+ if (a[i].compare) {
+ if (!a[i].compare(b[i])) return false;
+ }
+ if (a[i] !== b[i]) return false;
+ }
+ return true;
+ }
+};
View
29 vendor/plugins/blue-ridge/lib/smoke.stub.js
@@ -0,0 +1,29 @@
+Smoke.Stub = function(obj,attr) {
+ this.obj = obj;
+ this.attribute = attr;
+ this.and_return(this.defaultReturn);
+};
+
+Smoke.Stub.prototype = {
+ defaultReturn: null,
+ property: function(p){
+ this.property = p;
+ this.and_set_to(this.defaultReturn);
+ return this
+ },
+ method: function(f){
+ this.func = f;
+ this.and_return(this.defaultReturn);
+ return this
+ },
+ and_return: function(v){
+ this.obj[this.attribute] = function() {
+ return v
+ };
+ return this.obj
+ },
+ and_set_to: function(v){
+ this.obj[this.attribute] = v;
+ return this.obj
+ }
+};
View
50 vendor/plugins/blue-ridge/lib/test_runner.js
@@ -0,0 +1,50 @@
+// NOTE: This script expects to be ran from the #{RAILS_ROOT}/[test|spec|examples]/javascript directory!
+
+if(arguments.length == 0) {
+ print("Usage: test_runner.js spec/javascripts/file_spec.js");
+ quit(1);
+}
+
+function require(file, options){
+ load(file);
+
+ options = options || {};
+ if(options['onload']) {
+ options['onload'].call();
+ }
+}
+
+function debug(message){
+ print(message);
+}
+
+// Mock up the Firebug API for convenience.
+var console = {debug:debug};
+
+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/";
+
+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(spec_file);
+jQuery(window).trigger("load");
View
62 vendor/plugins/blue-ridge/tasks/javascript_testing_tasks.rake
@@ -0,0 +1,62 @@
+plugin_prefix = "#{RAILS_ROOT}/vendor/plugins/blue-ridge"
+rhino_command = "java -jar #{plugin_prefix}/lib/js.jar -w -debug"
+test_runner_command = "#{rhino_command} #{plugin_prefix}/lib/test_runner.js"
+
+def find_base_dir
+ target_dirs = ["test/javascript", "spec/javascripts", "examples/javascripts"]
+ base_dir = target_dirs.find {|d| File.exist?(d) }
+ raise "Could not find JavaScript test directory.\nNone of the following directories existed: #{target_dirs.join(", ")}.\nMaybe you need to call './script/generate blue_ridge'?" unless base_dir
+ base_dir
+end
+
+# Support Test::Unit & Test/Spec style
+namespace :test do
+ desc "Runs all the JavaScript tests and outputs the results"
+ task :javascripts do
+ Dir.chdir(find_base_dir) do
+ all_fine = true
+ if ENV["TEST"]
+ all_fine = false unless system("#{test_runner_command} #{ENV["TEST"]}_spec.js")
+ else
+ Dir.glob("**/*_spec.js").each do |file|
+ all_fine = false unless system("#{test_runner_command} #{file}")
+ end
+ end
+ raise "JavaScript test failures" unless all_fine
+ end
+ end
+
+ task :javascript => :javascripts
+end
+
+# Support RSpec style
+namespace :spec do
+ task :javascripts => ["test:javascripts"]
+ task :javascript => ["test:javascripts"]
+end
+
+# Support Micronaut style
+namespace :examples do
+ task :javascripts => ["test:javascripts"]
+ task :javascript => ["test:javascripts"]
+end
+
+
+namespace :js do
+ task :fixtures do
+ fixture_dir = "#{RAILS_ROOT}/#{find_base_dir}/fixtures"
+
+ if PLATFORM[/darwin/]
+ system("open #{fixture_dir}")
+ elsif PLATFORM[/linux/]
+ system("firefox #{fixture_dir}")
+ else
+ puts "You can run your in-browser fixtures from #{fixture_dir}."
+ end
+ end
+
+ task :shell do
+ rlwrap = `which rlwrap`.chomp
+ system("#{rlwrap} #{rhino_command} -f #{plugin_prefix}/lib/shell.js -f -")
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.