o: ActiveSupport::Cache::Entry :@compressedF:@expires_in0:@created_atf1361302430.933271: @value"Â'{I" class:EFI"BundledAsset;FI"logical_path;FI"$teabag/phantomjs/runner_spec.js;TI" pathname;FI"Z/Users/jejacks0n/Projects/teabag/spec/javascripts/teabag/phantomjs/runner_spec.coffee;FI"content_type;FI"application/javascript;FI" mtime;FI"2013-02-16T14:42:32-07:00;FI" length;FiØ%I" digest;F"%e184e86ce751cceae5bb5d867c5f9fe5I" source;FI"Ø%(function() { window.phantom = { exit: function() {} }; window.require = function(file) { switch (file) { case "system": return { args: ["runner.coffee", "http://host:port/path", "200"] }; case "webpage": return { create: function() { return { open: function() { return {}; }, evaluate: function() { return {}; } }; } }; } }; describe("PhantomJS Runner", function() { beforeEach(function() { this.logSpy = spyOn(window.console, "log"); return this.runner = new Runner(); }); describe("constructor", function() { it("sets the url from system.args", function() { return expect(this.runner.url).toBe("http://host:port/path"); }); return it("sets the timeout from system.args", function() { return expect(this.runner.timeout).toBe(200 * 1000); }); }); describe("#run", function() { beforeEach(function() { this.initSpy = spyOn(this.runner, "initPage"); return this.loadSpy = spyOn(this.runner, "loadPage"); }); it("calls initPage", function() { this.runner.run(); return expect(this.initSpy).toHaveBeenCalled(); }); return it("calls loadPage", function() { this.runner.run(); return expect(this.loadSpy).toHaveBeenCalled(); }); }); describe("#initPage", function() { return it("creates a webpage and assigns it to @page", function() { this.runner.initPage(); return expect(typeof this.runner.page["open"]).toBe("function"); }); }); describe("#loadPage", function() { beforeEach(function() { return this.runner.initPage(); }); it("opens the url in the page", function() { var spy; spy = spyOn(this.runner.page, "open"); this.runner.loadPage(); return expect(spy).toHaveBeenCalledWith(this.runner.url); }); return it("attaches all the methods to page", function() { spyOn(this.runner, "pageCallbacks").andCallFake(function() { return { callback1: "method1", callback2: "method2" }; }); this.runner.loadPage(); expect(this.runner.page.callback1).toBe("method1"); return expect(this.runner.page.callback2).toBe("method2"); }); }); describe("#waitForResults", function() { beforeEach(function() { this.timeoutSpy = spyOn(window, "setTimeout"); return this.runner.initPage(); }); it("evaluates in the context of the page", function() { var spy; spy = spyOn(this.runner.page, "evaluate").andReturn(false); this.runner.waitForResults(); return expect(spy).toHaveBeenCalled(); }); it("sets a timeout of 100ms if not finished", function() { spyOn(this.runner.page, "evaluate").andReturn(false); this.runner.waitForResults(); return expect(this.timeoutSpy).toHaveBeenCalled(); }); return it("calls finish if Teabag says that it's finished", function() { var spy; spyOn(this.runner.page, "evaluate").andCallFake(function(f) { return f(); }); spy = spyOn(this.runner, "finish"); window.Teabag.finished = true; this.runner.waitForResults(); return expect(spy).toHaveBeenCalled(); }); }); describe("#fail", function() { it("logs the error message", function() { this.runner.fail("_message_"); expect(this.logSpy).toHaveBeenCalledWith("Error: _message_"); return expect(this.logSpy).toHaveBeenCalledWith('{"_teabag":true,"type":"exception"}'); }); return it("exits with the error code", function() { var spy; spy = spyOn(phantom, "exit"); this.runner.fail("_message_", 2); return expect(spy).toHaveBeenCalledWith(2); }); }); describe("#finish", function() { it("logs an empty string (to fix line feeds in the console)", function() { this.runner.finish(); return expect(this.logSpy).toHaveBeenCalledWith(" "); }); return it("calls exit with a success code", function() { var spy; spy = spyOn(phantom, "exit"); this.runner.finish(); return expect(spy).toHaveBeenCalledWith(0); }); }); describe("#pageCallbacks", function() { return it("returns an object with the expected methods", function() { var object; if (!Object.keys) { return; } object = this.runner.pageCallbacks(); return expect(Object.keys(object)).toEqual(["onError", "onConsoleMessage", "onLoadFinished"]); }); }); return describe("callback method", function() { beforeEach(function() { return this.callbacks = this.runner.pageCallbacks(); }); describe("#onError", function() { return it("logs the json of a message and trace", function() { this.callbacks.onError("_message_", ["trace1", "trace2"]); return expect(this.logSpy).toHaveBeenCalledWith('{"_teabag":true,"type":"error","message":"_message_","trace":["trace1","trace2"]}'); }); }); describe("#onConsoleMessage", function() { return it("logs the message", function() { this.callbacks.onConsoleMessage("_message_"); return expect(this.logSpy).toHaveBeenCalledWith("_message_"); }); }); return describe("#onLoadFinish", function() { beforeEach(function() { this.runner.initPage(); return this.waitSpy = spyOn(this.runner, "waitForResults"); }); it("fails if the status was not success", function() { var evalSpy, spy; spy = spyOn(this.runner, "fail"); evalSpy = spyOn(this.runner.page, "evaluate").andReturn(true); this.callbacks.onLoadFinished("failure"); expect(spy).toHaveBeenCalledWith("Failed to load: " + this.runner.url); expect(evalSpy).toHaveBeenCalled(); return expect(this.waitSpy).wasNotCalled(); }); return it("calls waitForResults", function() { this.callbacks.onLoadFinished("success"); return expect(this.waitSpy).toHaveBeenCalled(); }); }); }); }); }).call(this); (function() { var system, webpage, __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; system = require("system"); webpage = require("webpage"); this.Runner = (function() { function Runner() { this.waitForResults = __bind(this.waitForResults, this); this.url = system.args[1]; this.timeout = parseInt(system.args[2] || 180) * 1000; } Runner.prototype.run = function() { this.initPage(); return this.loadPage(); }; Runner.prototype.initPage = function() { this.page = webpage.create(); return this.page.viewportSize = { width: 800, height: 800 }; }; Runner.prototype.loadPage = function() { var method, name, _ref, _results; this.page.open(this.url); _ref = this.pageCallbacks(); _results = []; for (name in _ref) { method = _ref[name]; _results.push(this.page[name] = method); } return _results; }; Runner.prototype.waitForResults = function() { var finished; if ((new Date().getTime() - this.start) >= this.timeout) { this.fail("Timed out"); } finished = this.page.evaluate(function() { return window.Teabag && window.Teabag.finished; }); if (finished) { return this.finish(); } else { return setTimeout(this.waitForResults, 200); } }; Runner.prototype.fail = function(msg, errno) { if (msg == null) { msg = null; } if (errno == null) { errno = 1; } if (msg) { console.log("Error: " + msg); } console.log(JSON.stringify({ _teabag: true, type: "exception" })); return phantom.exit(errno); }; Runner.prototype.finish = function() { console.log(" "); return phantom.exit(0); }; Runner.prototype.pageCallbacks = function() { var _this = this; return { onError: function(message, trace) { console.log(JSON.stringify({ _teabag: true, type: "error", message: message, trace: trace })); return _this.errored = true; }, onConsoleMessage: function(msg) { console.log(msg); if (_this.errorTimeout) { clearTimeout(_this.errorTimeout); } if (_this.errored) { _this.errorTimeout = setTimeout((function() { return _this.fail('Javascript error has cause a timeout.'); }), 1000); return _this.errored = false; } }, onLoadFinished: function(status) { var defined; if (_this.start) { return; } _this.start = new Date().getTime(); defined = _this.page.evaluate(function() { return window.Teabag; }); if (!(status === "success" && defined)) { _this.fail("Failed to load: " + _this.url); return; } return _this.waitForResults(); } }; }; return Runner; })(); new Runner().run(); }).call(this); ;FI"required_assets_digest;F"%58fb477d2b6632066fd28d55384ad3fbI" _version;F"%6776f581a4329e299531e1d52aa59832