From bf59cf7ad7b634b007eca940449750957d9687af Mon Sep 17 00:00:00 2001 From: Adam Strickland Date: Wed, 26 Jun 2013 12:30:41 -0500 Subject: [PATCH 1/2] ignoring tmp dir --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 38f07db..c233401 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ node_modules .fseventsd Desktop DB Desktop DF +tmp/* From ebe5a51835824dbf474dd4e7d34c1d9d507caede Mon Sep 17 00:00:00 2001 From: Adam Strickland Date: Wed, 26 Jun 2013 12:31:05 -0500 Subject: [PATCH 2/2] adding :server_mount option --- lib/guard/jasmine.rb | 3 ++- lib/guard/jasmine/phantomjs/guard-jasmine.js | 6 ++++++ lib/guard/jasmine/phantomjs/lib/console.js | 10 +++++++++- lib/guard/jasmine/phantomjs/lib/reporter.js | 6 +++++- lib/guard/jasmine/phantomjs/lib/result.js | 15 +++++++++++---- spec/guard/jasmine_spec.rb | 16 +++++++++++++++- 6 files changed, 48 insertions(+), 8 deletions(-) diff --git a/lib/guard/jasmine.rb b/lib/guard/jasmine.rb index 863ea5f..b57d258 100644 --- a/lib/guard/jasmine.rb +++ b/lib/guard/jasmine.rb @@ -25,6 +25,7 @@ class Jasmine < Guard server: :auto, server_env: ENV['RAILS_ENV'] || 'development', server_timeout: 60, + server_mount: '/jasmine', port: nil, rackup_config: nil, jasmine_url: nil, @@ -91,7 +92,7 @@ def initialize(watchers = [], options = { }) options[:port] ||= Jasmine.find_free_server_port options[:server] ||= :auto options[:server] = ::Guard::Jasmine::Server.detect_server(options[:spec_dir]) if options[:server] == :auto - options[:jasmine_url] = "http://localhost:#{ options[:port] }#{ options[:server] == :jasmine_gem ? '/' : '/jasmine' }" unless options[:jasmine_url] + options[:jasmine_url] = "http://localhost:#{ options[:port] }#{ options[:server] == :jasmine_gem ? '/' : options[:server_mount] }" unless options[:jasmine_url] options[:specdoc] = :failure if ![:always, :never, :failure].include? options[:specdoc] options[:phantomjs_bin] = Jasmine.which('phantomjs') unless options[:phantomjs_bin] diff --git a/lib/guard/jasmine/phantomjs/guard-jasmine.js b/lib/guard/jasmine/phantomjs/guard-jasmine.js index 68c8be4..89cf3d4 100644 --- a/lib/guard/jasmine/phantomjs/guard-jasmine.js +++ b/lib/guard/jasmine/phantomjs/guard-jasmine.js @@ -32,6 +32,7 @@ page.onConsoleMessage = function(msg, line, source) { var result; + if (/^RUNNER_END$/.test(msg)) { result = page.evaluate(function() { return window.reporter.runnerResult; @@ -62,6 +63,7 @@ page.open(options.url, function(status) { var done, error, runnerAvailable, text; + page.onLoadFinished = function() {}; if (status !== 'success') { console.log(JSON.stringify({ @@ -80,6 +82,7 @@ } else { text = page.evaluate(function() { var _ref; + return (_ref = document.getElementsByTagName('body')[0]) != null ? _ref.innerText : void 0; }); if (text) { @@ -105,6 +108,7 @@ waitFor = function(test, ready, timeout) { var condition, interval, start, wait; + if (timeout == null) { timeout = 5000; } @@ -112,12 +116,14 @@ condition = false; wait = function() { var error, text; + if ((new Date().getTime() - start < timeout) && !condition) { return condition = test(); } else { if (!condition) { text = page.evaluate(function() { var _ref; + return (_ref = document.getElementsByTagName('body')[0]) != null ? _ref.innerText : void 0; }); if (text) { diff --git a/lib/guard/jasmine/phantomjs/lib/console.js b/lib/guard/jasmine/phantomjs/lib/console.js index d03550e..34cc39b 100644 --- a/lib/guard/jasmine/phantomjs/lib/console.js +++ b/lib/guard/jasmine/phantomjs/lib/console.js @@ -3,32 +3,37 @@ __slice = [].slice; Console = (function() { - function Console(console) { var log; + log = console.log; console.log = function() { var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; return log.call(console, Console.format.apply(Console, args)); }; console.info = function() { var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; return log.call(console, "INFO: " + (Console.format.apply(Console, args))); }; console.warn = function() { var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; return log.call(console, "WARN: " + (Console.format.apply(Console, args))); }; console.error = function() { var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; return log.call(console, "ERROR: " + (Console.format.apply(Console, args))); }; console.debug = function() { var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; return log.call(console, "DEBUG: " + (Console.format.apply(Console, args))); }; @@ -39,6 +44,7 @@ Console.format = function() { var arg, args, result, _i, _len, _this = this; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; result = []; if (typeof args[0] === 'string' && /%[sdifo]/gi.test(args[0])) { @@ -56,6 +62,7 @@ Console.inspect = function(object, type) { var match, result; + switch (type) { case '%s': result = String(object); @@ -93,6 +100,7 @@ Console.pp = function(object, depth) { var key, result, type, value, _i, _len; + if (depth == null) { depth = 0; } diff --git a/lib/guard/jasmine/phantomjs/lib/reporter.js b/lib/guard/jasmine/phantomjs/lib/reporter.js index 6fefd76..e18e225 100644 --- a/lib/guard/jasmine/phantomjs/lib/reporter.js +++ b/lib/guard/jasmine/phantomjs/lib/reporter.js @@ -2,7 +2,6 @@ var ConsoleReporter; ConsoleReporter = (function() { - function ConsoleReporter() {} ConsoleReporter.prototype.runnerResult = { @@ -27,6 +26,7 @@ ConsoleReporter.prototype.reportSpecResults = function(spec) { var messages, result, specResult, _base, _i, _len, _name, _ref; + if (!spec.results().skipped) { specResult = { id: spec.id, @@ -52,6 +52,7 @@ ConsoleReporter.prototype.reportSuiteResults = function(suite) { var parent, suiteResult, _base, _ref; + if (!suite.results().skipped) { suiteResult = { id: suite.id, @@ -77,6 +78,7 @@ ConsoleReporter.prototype.reportRunnerResults = function(runner) { var end, runtime; + runtime = (new Date().getTime() - this.startTime) / 1000; this.runnerResult['passed'] = runner.results().failedCount === 0; this.runnerResult['stats'] = { @@ -99,6 +101,7 @@ ConsoleReporter.prototype.addNestedSuites = function(suiteResult) { var suite, _i, _len, _ref, _results; + if (this.nestedSuiteResults[suiteResult.id]) { _ref = this.nestedSuiteResults[suiteResult.id]; _results = []; @@ -113,6 +116,7 @@ ConsoleReporter.prototype.removeEmptySuites = function(suiteResult) { var suite, suites, _i, _len, _ref; + suites = []; _ref = suiteResult.suites; for (_i = 0, _len = _ref.length; _i < _len; _i++) { diff --git a/lib/guard/jasmine/phantomjs/lib/result.js b/lib/guard/jasmine/phantomjs/lib/result.js index 4648859..1abdbb9 100644 --- a/lib/guard/jasmine/phantomjs/lib/result.js +++ b/lib/guard/jasmine/phantomjs/lib/result.js @@ -1,9 +1,7 @@ -// Generated by CoffeeScript 1.3.3 (function() { var Result; Result = (function() { - function Result(result, logs, errors, options) { this.result = result; this.logs = logs != null ? logs : {}; @@ -13,8 +11,10 @@ Result.prototype.addLogs = function(suite) { var id, s, spec; + suite.suites = (function() { var _i, _len, _ref, _results; + _ref = suite.suites; _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { @@ -26,6 +26,7 @@ if (suite.specs) { suite.specs = (function() { var _i, _len, _ref, _results; + _ref = suite.specs; _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { @@ -46,8 +47,10 @@ Result.prototype.addErrors = function(suite) { var id, s, spec; + suite.suites = (function() { var _i, _len, _ref, _results; + _ref = suite.suites; _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { @@ -59,6 +62,7 @@ if (suite.specs) { suite.specs = (function() { var _i, _len, _ref, _results; + _ref = suite.specs; _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { @@ -77,8 +81,9 @@ return suite; }; - Result.prototype.addGlobalErrors = function(suite) { + Result.prototype.addGlobalError = function(suite) { var b, err, errMsg, globalErrors, noSpecs, noSuites, _i, _len, _ref; + noSuites = !suite.suites || suite.suites.length === 0; noSpecs = !suite.specs || suite.specs.length === 0; globalErrors = this.errors[-1] && this.errors[-1].length !== 0; @@ -97,8 +102,10 @@ Result.prototype.cleanResult = function(suite) { var s, spec, _i, _len, _ref; + suite.suites = (function() { var _i, _len, _ref, _results; + _ref = suite.suites; _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { @@ -125,7 +132,7 @@ } if (this.options.errors !== 'never') { this.addErrors(this.result); - this.addGlobalErrors(this.result); + this.addGlobalError(this.result); } this.cleanResult(this.result); return this.result; diff --git a/spec/guard/jasmine_spec.rb b/spec/guard/jasmine_spec.rb index 88a52f2..7faa044 100644 --- a/spec/guard/jasmine_spec.rb +++ b/spec/guard/jasmine_spec.rb @@ -31,6 +31,10 @@ guard.options[:server_timeout].should eql 60 end + it 'sets a default :server_mount option' do + guard.options[:server_mount].should eql defaults[:server_mount] + end + it 'finds a free port for the :port option' do Guard::Jasmine.should_receive(:find_free_server_port).and_return 9999 guard = Guard::Jasmine.new @@ -166,6 +170,7 @@ server: :jasmine_gem, server_env: 'test', server_timeout: 20, + server_mount: '/foo', port: 4321, rackup_config: 'spec/dummy/config.ru', jasmine_url: 'http://192.168.1.5/jasmine', @@ -204,6 +209,10 @@ guard.options[:server_timeout].should eql 20 end + it 'sets the :server_mount option' do + guard.options[:server_mount].should eq '/foo' + end + it 'sets the :port option' do guard.options[:port].should eql 4321 end @@ -303,10 +312,15 @@ guard.options[:jasmine_url].should eql 'http://localhost:4321/' end - it 'sets the jasminerice url' do + it 'sets the jasminerice url by default' do guard = Guard::Jasmine.new(nil, { server: :thin, port: 4321 }) guard.options[:jasmine_url].should eql 'http://localhost:4321/jasmine' end + + it 'sets the jasmine runner url as configured' do + guard = Guard::Jasmine.new(nil, { server: :thin, port: 4321, server_mount: '/specs' }) + guard.options[:jasmine_url].should eql 'http://localhost:4321/specs' + end end context 'with run all options' do