diff --git a/coffee.watchr b/coffee.watchr index 88d3123..263d0d5 100644 --- a/coffee.watchr +++ b/coffee.watchr @@ -1,18 +1,13 @@ require 'coffee-script' -FILE = 'jasmine/jasmine.headless-reporter.coffee' if !self.class.const_defined?(:FILE) -TARGET = FILE.gsub('.coffee', '.js') if !self.class.const_defined?(:TARGET) +watch('(jasmine/.*)\.coffee') { |m| coffee(m[1]) } -watch(FILE) { coffee } - -def coffee +def coffee(file) begin - File.open(TARGET, 'w') { |fh| fh.print CoffeeScript.compile File.open(FILE) } - puts "Wrote #{TARGET}" + File.open(file + '.js', 'w') { |fh| fh.print CoffeeScript.compile File.open(file + '.coffee') } + puts "Wrote #{file}" rescue Exception => e puts e.message end end -coffee - diff --git a/jasmine/console.coffee b/jasmine/console.coffee new file mode 100644 index 0000000..c1349a9 --- /dev/null +++ b/jasmine/console.coffee @@ -0,0 +1,58 @@ +class window.Inspector + constructor: (data) -> + @data = data + @examinedObjects = [] + run: -> + for property in this.inspect([], @data) + do (property) => + JHW.log(property.report()) + inspect: (output, data, indent = 0, key = null) -> + for obj in @examinedObjects + if obj == data + JHW.log("loop") + output.push(new InspectedProperty("<< LOOP >>", key, indent)) + return output + @examinedObjects.push(data) + + switch typeof(data) + when 'undefined' + output.push(new InspectedProperty('undefined', key, indent)) + when 'string', 'number', 'boolean' + output.push(new InspectedProperty(data, key, indent)) + else + output.push(new DefinedObject(key, indent)) + for newKey, value of data + JHW.log("trying #{newKey}") + if data.hasOwnProperty(newKey) + this.inspect(output, value, indent + 1, newKey) + output + +class window.IntendableProperty + indentString: (output) -> + if @key? + output = "#{@key}: #{output}" + if @indent > 0 + for i in [1..@indent] + do (i) => + output = " " + output + output + +class window.DefinedObject extends window.IntendableProperty + constructor: (key, indent) -> + @key = key + @indent = indent + report: -> + this.indentString("Object") + +class window.InspectedProperty extends window.IntendableProperty + constructor: (data, key, indent) -> + @data = data + @key = key + @indent = indent + report: -> + output = switch typeof(@data) + when 'string' + "\"#{@data}\"" + else + @data + this.indentString(output) diff --git a/jasmine/console.js b/jasmine/console.js new file mode 100644 index 0000000..391d0f8 --- /dev/null +++ b/jasmine/console.js @@ -0,0 +1,120 @@ +(function() { + var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) { + for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } + function ctor() { this.constructor = child; } + ctor.prototype = parent.prototype; + child.prototype = new ctor; + child.__super__ = parent.prototype; + return child; + }; + window.Inspector = (function() { + function Inspector(data) { + this.data = data; + this.examinedObjects = []; + } + Inspector.prototype.run = function() { + var property, _i, _len, _ref, _results; + _ref = this.inspect([], this.data); + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + property = _ref[_i]; + _results.push(__bind(function(property) { + return JHW.log(property.report()); + }, this)(property)); + } + return _results; + }; + Inspector.prototype.inspect = function(output, data, indent, key) { + var newKey, obj, value, _i, _len, _ref; + if (indent == null) { + indent = 0; + } + if (key == null) { + key = null; + } + _ref = this.examinedObjects; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + obj = _ref[_i]; + if (obj === data) { + JHW.log("loop"); + output.push(new InspectedProperty("<< LOOP >>", key, indent)); + return output; + } + } + this.examinedObjects.push(data); + switch (typeof data) { + case 'undefined': + output.push(new InspectedProperty('undefined', key, indent)); + break; + case 'string': + case 'number': + case 'boolean': + output.push(new InspectedProperty(data, key, indent)); + break; + default: + output.push(new DefinedObject(key, indent)); + for (newKey in data) { + value = data[newKey]; + JHW.log("trying " + newKey); + if (data.hasOwnProperty(newKey)) { + this.inspect(output, value, indent + 1, newKey); + } + } + } + return output; + }; + return Inspector; + })(); + window.IntendableProperty = (function() { + function IntendableProperty() {} + IntendableProperty.prototype.indentString = function(output) { + var i, _fn, _ref; + if (this.key != null) { + output = "" + this.key + ": " + output; + } + if (this.indent > 0) { + _fn = __bind(function(i) { + return output = " " + output; + }, this); + for (i = 1, _ref = this.indent; 1 <= _ref ? i <= _ref : i >= _ref; 1 <= _ref ? i++ : i--) { + _fn(i); + } + } + return output; + }; + return IntendableProperty; + })(); + window.DefinedObject = (function() { + function DefinedObject(key, indent) { + this.key = key; + this.indent = indent; + } + __extends(DefinedObject, window.IntendableProperty); + DefinedObject.prototype.report = function() { + return this.indentString("Object"); + }; + return DefinedObject; + })(); + window.InspectedProperty = (function() { + function InspectedProperty(data, key, indent) { + this.data = data; + this.key = key; + this.indent = indent; + } + __extends(InspectedProperty, window.IntendableProperty); + InspectedProperty.prototype.report = function() { + var output; + output = (function() { + switch (typeof this.data) { + case 'string': + return "\"" + this.data + "\""; + break; + default: + return this.data; + } + }).call(this); + return this.indentString(output); + }; + return InspectedProperty; + })(); +}).call(this); diff --git a/lib/jasmine/cli.rb b/lib/jasmine/cli.rb index 21c39f8..1eb837a 100644 --- a/lib/jasmine/cli.rb +++ b/lib/jasmine/cli.rb @@ -35,7 +35,7 @@ module Jasmine Jasmine Test Runner #{files.join("\n")}