Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don't worry, you can still create the pull request.
  • 5 commits
  • 13 files changed
  • 2 commit comments
  • 2 contributors
Commits on Aug 11, 2009
@bartaz bartaz console output format changed 5c6d30b
Larry Karnowski and Jason Rudolph Tested & refactored Ruby code into a BlueRidge module
	- moved common rake and generator Ruby into a blue_ridge.rb file
	- added Micronaut & Mocha-based tests for BlueRidge Ruby code
	- default "rake" task runs both Ruby & JavaScript specs
	- fixed "rake js:fixtures" for Micronaut 'examples' directory
	- fixed bug where JavaScript specs would not generate in the Micronaut
	  'examples' directory

Signed-off-by: Bartek Szopka <bartek.szopka+github@gmail.com>
5e339f0
Commits on Aug 12, 2009
@bartaz bartaz screw.builder updated 7be3026
@bartaz bartaz updated blue-ridge initialization d755e13
@bartaz bartaz closing tags to fix env.js complains 59d2296
View
13 Rakefile
@@ -1,4 +1,15 @@
ENV["BLUE_RIDGE_PREFIX"] = File.dirname(__FILE__)
import File.dirname(__FILE__) + '/tasks/javascript_testing_tasks.rake'
-task :default => "test:javascripts"
+gem "spicycode-micronaut", ">= 0.2.4"
+require 'micronaut'
+require 'micronaut/rake_task'
+
+namespace :test do
+ desc "Run all micronaut examples using rcov"
+ Micronaut::RakeTask.new :rubies do |t|
+ t.pattern = "spec/rubies/**/*_spec.rb"
+ end
+end
+
+task :default => ["test:rubies", "test:javascripts"]
View
9 generators/blue_ridge/blue_ridge_generator.rb
@@ -1,6 +1,10 @@
+require File.expand_path(File.dirname(__FILE__) + '/../../lib/blue_ridge')
+
class BlueRidgeGenerator < Rails::Generator::Base
def manifest
record do |m|
+ base_dir = BlueRidge.javascript_spec_dir
+
m.directory base_dir
m.file 'application_spec.js', "#{base_dir}/application_spec.js"
m.file 'spec_helper.js', "#{base_dir}/spec_helper.js"
@@ -10,9 +14,4 @@ def manifest
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
6 generators/javascript_spec/javascript_spec_generator.rb
@@ -3,6 +3,8 @@ def manifest
file_path_with_spec, file_path_without_spec = file_path_with_and_without_spec
record do |m|
+ base_dir = BlueRidge.javascript_spec_dir
+
m.directory base_dir
m.directory "#{base_dir}/fixtures"
@@ -12,10 +14,6 @@ def manifest
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$/, "")]
View
61 lib/blue-ridge.js
@@ -1,7 +1,7 @@
var BLUE_RIDGE_LIB_PREFIX = BLUE_RIDGE_LIB_PREFIX || "../../vendor/plugins/blue-ridge/lib/";
var BlueRidge = {
- require: function(url, options){
+ require: function(url, callback){
// add a '../' prefix to all JavaScript paths because we expect to be ran from one of:
// * test/javascript/fixtures
// * specs/javascripts/fixtures
@@ -12,13 +12,20 @@ var BlueRidge = {
var script = document.createElement("script");
script.src = url;
- options = options || {};
-
- if(options['onload']) {
- // Attach handlers for all browsers
- script.onload = script.onreadystatechange = options['onload'];
- }
-
+ if(callback){
+ var done = false;
+ // Attach handlers for all browsers
+ script.onload = script.onreadystatechange = function(){
+ if (!done && (!this.readyState ||
+ this.readyState == "loaded" || this.readyState == "complete") ) {
+ done = true;
+ callback.call();
+ // Handle memory leak in IE
+ script.onload = script.onreadystatechange = null;
+ head.removeChild( script );
+ }
+ };
+ };
head.appendChild(script);
},
@@ -35,16 +42,30 @@ var BlueRidge = {
var require = require || BlueRidge.require;
var debug = debug || BlueRidge.debug;
-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");
+// all required js libs are now nested to load properly
+
+require(BLUE_RIDGE_LIB_PREFIX + "jquery-1.3.2.js", function(){
+ require(BLUE_RIDGE_LIB_PREFIX + "jquery.fn.js", function(){
+ require(BLUE_RIDGE_LIB_PREFIX + "jquery.print.js", function(){
+ require(BLUE_RIDGE_LIB_PREFIX + "screw.builder.js", function(){
+ require(BLUE_RIDGE_LIB_PREFIX + "screw.matchers.js", function(){
+ require(BLUE_RIDGE_LIB_PREFIX + "screw.events.js", function(){
+ require(BLUE_RIDGE_LIB_PREFIX + "screw.behaviors.js", function(){
+ require(BLUE_RIDGE_LIB_PREFIX + "smoke.core.js", function(){
+ require(BLUE_RIDGE_LIB_PREFIX + "smoke.mock.js", function(){
+ require(BLUE_RIDGE_LIB_PREFIX + "smoke.stub.js", function(){
+ require(BLUE_RIDGE_LIB_PREFIX + "screw.mocking.js",function(){
+ require(BlueRidge.deriveSpecNameFromCurrentFile());
+ });
+ });
+ });
+ });
+ });
+ });
+ });
+ });
+ });
+ });
+});
+
-require(BlueRidge.deriveSpecNameFromCurrentFile());
View
50 lib/blue_ridge.rb
@@ -0,0 +1,50 @@
+module BlueRidge
+ JavaScriptSpecDirs = ["examples/javascripts", "spec/javascripts", "test/javascript"]
+
+ def self.plugin_prefix
+ ENV["BLUE_RIDGE_PREFIX"] || "#{RAILS_ROOT}/vendor/plugins/blue-ridge"
+ end
+
+ def self.rhino_command
+ "java -Dblue.ridge.prefix=\"#{plugin_prefix}\" -jar #{plugin_prefix}/lib/js.jar -w -debug"
+ end
+
+ def self.test_runner_command
+ "#{rhino_command} #{plugin_prefix}/lib/test_runner.js"
+ end
+
+ def self.find_base_spec_dir
+ return "examples" if File.exist?("examples")
+ return "spec" if File.exist?("spec")
+ "test"
+ end
+
+ def self.javascript_spec_dir
+ base_spec_dir = find_base_spec_dir
+ return "test/javascript" if base_spec_dir == "test"
+ base_spec_dir + "/javascripts"
+ end
+
+ def self.find_javascript_spec_dir
+ JavaScriptSpecDirs.find {|d| File.exist?(d) }
+ end
+
+ def self.find_specs_under_current_dir
+ Dir.glob("*_spec.js")
+ end
+
+ def self.run_spec(spec_filename)
+ system("#{test_runner_command} #{spec_filename}")
+ end
+
+ def self.run_specs_in_dir(spec_dir, spec_name = nil)
+ result = nil
+ Dir.chdir(spec_dir) { result = run_specs(spec_name) }
+ result
+ end
+
+ def self.run_specs(spec_name = nil)
+ specs = spec_name.nil? ? find_specs_under_current_dir : ["#{spec_name}_spec.js"]
+ all_fine = specs.inject(true) {|result, spec| result &= run_spec(spec) }
+ end
+end
View
68 lib/consoleReportForRake.js
@@ -1,20 +1,65 @@
(function($) {
+ var failedSpecs = [],
+ ESC = String.fromCharCode(27),
+ GREEN = ESC + "[32m",
+ RED = ESC + "[31m",
+ RESET = ESC + "[0m",
+
+// change it to false if your text output doesn't support colouring
+ coloured = true;
+
+ function printGreen(message){
+ if(coloured) { message = GREEN + message + RESET; }
+ print(message);
+ }
+
+ function printRed(message){
+ if(coloured) { message = RED + message + RESET; }
+ print(message);
+ }
+
$(Screw).bind("before", function(){
+ var currentContext = "";
+
+ function context_name(element){
+ var context_name = "";
+ $(element).parents(".describe").children("h1").each(function(){
+ context_name = $(this).text() + " " + context_name;
+ });
+ return context_name.replace(/^\s+|\s+$/g, '');
+ }
+
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 $(element).children("h2").text();
+ }
- return context_name + " - " + example_name;
+ function updateContext(context){
+ if(context != currentContext){
+ currentContext = context;
+ print("\n" + context);
+ }
+ };
+
+ function report(example, failReason){
+ var failed = typeof failReason != 'undefined',
+ context = context_name(example),
+ example = example_name(example),
+ print = failed ? printRed : printGreen,
+ message = " - " + example;
+ if (failed) {
+ message += " (FAILED - " + (failedSpecs.length+1) + ")";
+ failedSpecs.push([context, example, failReason])
+ }
+ updateContext(context);
+ print(message);
}
$('.it')
.bind('passed', function(){
- java.lang.System.out.print(".");
+ report(this);
})
.bind('failed', function(e, reason){
- print("\nFAILED: " + example_name(this));
- print(" " + reason + "\n");
+ report(this, reason);
});
});
@@ -22,11 +67,16 @@
var testCount = $('.passed').length + $('.failed').length;
var failures = $('.failed').length;
var elapsedTime = ((new Date() - Screw.suite_start_time)/1000.0);
-
+
print("\n")
+ $.each(failedSpecs, function(i, fail){
+ printRed((i+1) + ")");
+ printRed(fail[0] + " " + fail[1] + " FAILED:")
+ printRed(" " + fail[2] + "\n");
+ });
print(testCount + ' test(s), ' + failures + ' failure(s)');
print(elapsedTime.toString() + " seconds elapsed");
-
+
if(failures > 0) { java.lang.System.exit(1) };
});
})(jQuery);
View
4 lib/screw.builder.js
@@ -66,7 +66,7 @@ var Screw = (function($) {
$(screw).queue(function() { $(screw).trigger('loading') });
- $(window).load(function(){
+ $(function() {
$('<div class="describe"></div>')
.append('<h3 class="status"></h3>')
.append('<ol class="befores"></ol>')
@@ -79,4 +79,4 @@ var Screw = (function($) {
});
return screw;
-})(jQuery);
+})(jQuery);
View
7 lib/test_runner.js
@@ -6,12 +6,11 @@ if(arguments.length == 0) {
var PLUGIN_PREFIX = environment["blue.ridge.prefix"] || "../../vendor/plugins/blue-ridge";
var BlueRidge = {
- require: function(file, options){
+ require: function(file, callback){
load(file);
- options = options || {};
- if(options['onload']) {
- options['onload'].call();
+ if(callback) {
+ callback.call();
}
},
View
BIN  spec/.DS_Store
Binary file not shown
View
BIN  spec/javascripts/.DS_Store
Binary file not shown
View
155 spec/rubies/blue_ridge_spec.rb
@@ -0,0 +1,155 @@
+require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
+require File.expand_path(File.dirname(__FILE__) + '/../../lib/blue_ridge')
+
+describe BlueRidge do
+ describe "finding the top-level directory containing the project's tests" do
+ it "returns Micronaut's 'examples' directory if it exists" do
+ File.stubs(:exist?).with("examples").returns(true)
+ BlueRidge.find_base_spec_dir.should == "examples"
+ end
+
+ it "returns RSpec's 'spec' directory if it exists and no Micronaut directory exists" do
+ File.stubs(:exist?).with("examples").returns(false)
+ File.stubs(:exist?).with("spec").returns(true)
+ BlueRidge.find_base_spec_dir.should == "spec"
+ end
+
+ it "returns the 'test' directory if no Micronaut or RSpec directories exist" do
+ File.stubs(:exist?).with("examples").returns(false)
+ File.stubs(:exist?).with("spec").returns(false)
+ BlueRidge.find_base_spec_dir.should == "test"
+ end
+ end
+
+ describe "returning the directory name to contain the project's JavaScript tests" do
+ it "returns 'examples/javascripts' if the base spec dir is 'examples'" do
+ BlueRidge.stubs(:find_base_spec_dir).returns("examples")
+ BlueRidge.javascript_spec_dir.should == "examples/javascripts"
+ end
+
+ it "returns 'spec/javascripts' if the base spec dir is 'spec'" do
+ BlueRidge.stubs(:find_base_spec_dir).returns("spec")
+ BlueRidge.javascript_spec_dir.should == "spec/javascripts"
+ end
+
+ it "returns 'test/javascript' if the base spec dir is 'test'" do
+ BlueRidge.stubs(:find_base_spec_dir).returns("test")
+ BlueRidge.javascript_spec_dir.should == "test/javascript"
+ end
+ end
+
+ describe "finding the directory containing the project's JavaScript tests" do
+ it "returns 'examples/javascripts' if it exists" do
+ File.stubs(:exist?).with("examples/javascripts").returns(true)
+ BlueRidge.find_javascript_spec_dir.should == "examples/javascripts"
+ end
+
+ it "returns 'spec/javascripts' if it exists and 'examples/javascripts' does not" do
+ File.stubs(:exist?).with("examples/javascripts").returns(false)
+ File.stubs(:exist?).with("spec/javascripts").returns(true)
+ BlueRidge.find_javascript_spec_dir.should == "spec/javascripts"
+ end
+
+ it "returns 'test/javascript' if it exists and 'examples/javascripts' and 'spec/javascripts' do not" do
+ File.stubs(:exist?).with("examples/javascripts").returns(false)
+ File.stubs(:exist?).with("spec/javascripts").returns(false)
+ File.stubs(:exist?).with("test/javascript").returns(true)
+ BlueRidge.find_javascript_spec_dir.should == "test/javascript"
+ end
+
+ it "returns null if none of the JavaScript spec directories exist" do
+ File.stubs(:exist?).with("examples/javascripts").returns(false)
+ File.stubs(:exist?).with("spec/javascripts").returns(false)
+ File.stubs(:exist?).with("test/javascript").returns(false)
+ BlueRidge.find_javascript_spec_dir.should be_nil
+ end
+ end
+
+ describe "finding all spec names that live under the current directory" do
+ it "returns the list of '*_spec.js' filenames under the current directory" do
+ Dir.expects(:glob).with("*_spec.js").returns(:some_filenames)
+ BlueRidge.find_specs_under_current_dir.should == :some_filenames
+ end
+ end
+
+ describe "running a specific spec" do
+ it "runs the test runner command against the given spec filename in a separate process" do
+ BlueRidge.stubs(:test_runner_command).returns("some_test_runner_command")
+ BlueRidge.expects(:system).with("some_test_runner_command some_spec_file").returns(:some_value)
+ BlueRidge.run_spec("some_spec_file").should == :some_value
+ end
+ end
+
+ describe "runing all specs under a given directory" do
+ it "changes the current working directory to the given directory" do
+ Dir.expects(:chdir).with("some_directory")
+ BlueRidge.run_specs_in_dir("some_directory")
+ end
+
+ it "runs the specs passing in the given spec name" do
+ Dir.stubs(:chdir).yields
+ BlueRidge.expects(:run_specs).with("some_spec_name")
+ BlueRidge.run_specs_in_dir("some_directory", "some_spec_name")
+ end
+
+ it "returns the result of the running the specs" do
+ Dir.stubs(:chdir).yields
+ BlueRidge.stubs(:run_specs).returns(:some_value)
+ BlueRidge.run_specs_in_dir("some_directory").should == :some_value
+ end
+ end
+
+ describe "running specs under the current directory" do
+ describe "when the given spec filename is nil" do
+ it "calls run_spec for each '*_spec.js' file under the current directory" do
+ BlueRidge.stubs(:find_specs_under_current_dir).returns(["first_js_spec.js", "second_js_spec.js"])
+ BlueRidge.expects(:run_spec).with("first_js_spec.js")
+ BlueRidge.expects(:run_spec).with("second_js_spec.js")
+ BlueRidge.run_specs
+ end
+
+ it "calls run_spec for each of the spec files, even if an early one reports a failure" do
+ BlueRidge.stubs(:find_specs_under_current_dir).returns(["first_js_spec.js", "second_js_spec.js"])
+ BlueRidge.expects(:run_spec).with("first_js_spec.js").returns(false)
+ BlueRidge.expects(:run_spec).with("second_js_spec.js")
+ BlueRidge.run_specs
+ end
+
+ it "returns false if ANY of the specs reports a failure" do
+ BlueRidge.stubs(:find_specs_under_current_dir).returns(["first_js_spec.js", "second_js_spec.js"])
+ BlueRidge.stubs(:run_spec).with("first_js_spec.js").returns(false)
+ BlueRidge.stubs(:run_spec).with("second_js_spec.js").returns(true)
+ BlueRidge.run_specs.should == false
+ end
+
+ it "returns true if ALL of the specs reports success" do
+ BlueRidge.stubs(:find_specs_under_current_dir).returns(["first_js_spec.js", "second_js_spec.js"])
+ BlueRidge.stubs(:run_spec).returns(true)
+ BlueRidge.run_specs.should == true
+ end
+ end
+
+ describe "when given a spec name" do
+ it "runs only the single spec and does not look for other specs" do
+ BlueRidge.expects(:find_specs_under_current_dir).never
+ BlueRidge.expects(:run_spec).once
+ BlueRidge.run_specs("some_filename")
+ end
+
+ it "runs the corresponding spec file for the given spec name" do
+ BlueRidge.expects(:run_spec).with("some_filename_spec.js").returns(true)
+ BlueRidge.run_specs("some_filename").should == true
+ end
+
+ it "returns true if the spec reports success" do
+ BlueRidge.stubs(:run_spec).returns(true)
+ BlueRidge.run_specs("some_filename").should == true
+ end
+
+ it "returns false if the spec reports a failure" do
+ BlueRidge.stubs(:run_spec).returns(false)
+ BlueRidge.run_specs("some_filename").should == false
+ end
+ end
+ end
+end
View
14 spec/rubies/spec_helper.rb
@@ -0,0 +1,14 @@
+require "micronaut"
+
+def not_in_editor?
+ ['TM_MODE', 'EMACS', 'VIM'].all? { |k| !ENV.has_key?(k) }
+end
+
+Micronaut.configure do |config|
+ config.formatter = :progress
+ config.mock_with :mocha
+ config.color_enabled = not_in_editor?
+ config.filter_run :focused => true
+ config.alias_example_to :fit, :focused => true
+ config.profile_examples = false
+end
View
40 tasks/javascript_testing_tasks.rake
@@ -1,29 +1,18 @@
-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"
+require File.expand_path(File.dirname(__FILE__) + '/../lib/blue_ridge')
-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
+def error_message_for_missing_spec_dir
+ %Q{Could not find JavaScript test directory.
+None of the following directories existed: #{BlueRidge::JavaScriptSpecDirs.join(", ")}.
+Maybe you need to call './script/generate blue_ridge'?
+}
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
+ js_spec_dir = BlueRidge.find_javascript_spec_dir || (raise error_message_for_missing_spec_dir)
+ raise "JavaScript test failures" unless BlueRidge.run_specs_in_dir(js_spec_dir, ENV["TEST"])
end
task :javascript => :javascripts
@@ -31,20 +20,21 @@ end
# Support RSpec style
namespace :spec do
- task :javascripts => ["test:javascripts"]
- task :javascript => ["test:javascripts"]
+ task :javascripts => "test:javascripts"
+ task :javascript => "test:javascripts"
end
# Support Micronaut style
namespace :examples do
- task :javascripts => ["test:javascripts"]
- task :javascript => ["test:javascripts"]
+ task :javascripts => "test:javascripts"
+ task :javascript => "test:javascripts"
end
namespace :js do
task :fixtures do
- fixture_dir = "#{RAILS_ROOT}/#{find_base_dir}/fixtures"
+ js_spec_dir = BlueRidge.find_javascript_spec_dir || (raise error_message_for_missing_spec_dir)
+ fixture_dir = "#{js_spec_dir}/fixtures"
if PLATFORM[/darwin/]
system("open #{fixture_dir}")
@@ -57,6 +47,6 @@ namespace :js do
task :shell do
rlwrap = `which rlwrap`.chomp
- system("#{rlwrap} #{rhino_command} -f #{plugin_prefix}/lib/shell.js -f -")
+ system("#{rlwrap} #{BlueRidge.rhino_command} -f #{BlueRidge.plugin_prefix}/lib/shell.js -f -")
end
end

Showing you all comments on commits in this comparison.

@karnowski

Does this fix the problem with Screw.Unit never running in Safari 4?

@bartaz

It seems to fix problems I've had with webkit browsers (Chrome, Safari).

Something went wrong with that request. Please try again.