From b0e5924d6fb5d1ea12da2be4591764a3c425c16a Mon Sep 17 00:00:00 2001 From: Thomas Johansen Date: Fri, 10 Apr 2015 10:52:44 +0200 Subject: [PATCH] Fix and improve specs related to bootstrapping First and foremost fixes specs related to `Latex` and bootstrapping the global `window.latex` instance. --- spec/latex-spec.coffee | 25 +++++++++++++++---------- spec/spec-bootstrap.coffee | 9 ++------- spec/spec-helpers.coffee | 8 +------- spec/stubs.coffee | 16 ++++++++++++++++ 4 files changed, 34 insertions(+), 24 deletions(-) create mode 100644 spec/stubs.coffee diff --git a/spec/latex-spec.coffee b/spec/latex-spec.coffee index fe9531a6..bbf81031 100644 --- a/spec/latex-spec.coffee +++ b/spec/latex-spec.coffee @@ -1,17 +1,23 @@ helpers = require './spec-helpers' Latex = require '../lib/latex' +{Opener} = require './stubs' describe "Latex", -> - [latex] = [] + [latex, globalLatex] = [] beforeEach -> + globalLatex = window.latex + delete window.latex + latex = new Latex() + latex.initialize() + + afterEach -> + window.latex = globalLatex describe "initialize", -> it "initializes all properties", -> - opener = helpers.nullOpener() - spyOn(latex, 'resolveOpenerImplementation').andReturn(opener.constructor) - latex.initialize() + spyOn(latex, 'resolveOpenerImplementation').andReturn(Opener) expect(latex.builder).toBeDefined() expect(latex.logger).toBeDefined() @@ -19,7 +25,7 @@ describe "Latex", -> describe "setDefaultBuilder", -> it "sets the default builder to LatexmkBuilder", -> - origin = latex.builder + origin = latex.__builder latex.setDefaultBuilder() expect(origin).toBeUndefined() @@ -27,7 +33,7 @@ describe "Latex", -> describe "setDefaultLogger", -> it "sets the default logger to ConsoleLogger", -> - origin = latex.logger + origin = latex.__logger latex.setDefaultLogger() expect(origin).toBeUndefined() @@ -35,13 +41,12 @@ describe "Latex", -> describe "setDefaultOpener", -> it "sets the default logger as resolved", -> - origin = latex.opener - opener = helpers.nullOpener() - spyOn(latex, 'resolveOpenerImplementation').andReturn(opener.constructor) + origin = latex.__opener + spyOn(latex, 'resolveOpenerImplementation').andReturn(Opener) latex.setDefaultOpener() expect(origin).toBeUndefined() - expect(latex.opener.constructor.name).toBe opener.constructor.name + expect(latex.opener.constructor.name).toBe Opener.name describe "Logger proxy", -> [logger] = [] diff --git a/spec/spec-bootstrap.coffee b/spec/spec-bootstrap.coffee index e85f909a..8c436bde 100644 --- a/spec/spec-bootstrap.coffee +++ b/spec/spec-bootstrap.coffee @@ -1,11 +1,6 @@ Latex = require '../lib/latex' -Logger = require '../lib/logger' - -class NullLogger extends Logger - error: -> null - warning: -> null - info: -> null +{Logger} = require './stubs' window.latex = new Latex() latex.initialize() -latex.setLogger(new NullLogger()) +latex.setLogger(new Logger()) diff --git a/spec/spec-helpers.coffee b/spec/spec-helpers.coffee index 83adb1ea..588ec8fb 100644 --- a/spec/spec-helpers.coffee +++ b/spec/spec-helpers.coffee @@ -1,12 +1,8 @@ require './spec-bootstrap' + fs = require 'fs-plus' temp = require 'temp' wrench = require 'wrench' -Opener = require '../lib/opener' - -class NullOpener extends Opener - open: (filePath, texPath, lineNumber, callback) -> null - module.exports = cloneFixtures: -> @@ -30,5 +26,3 @@ module.exports = originalInterval = env.defaultTimeoutInterval env.defaultTimeoutInterval = interval originalInterval - - nullOpener: -> new NullOpener() diff --git a/spec/stubs.coffee b/spec/stubs.coffee new file mode 100644 index 00000000..36112d60 --- /dev/null +++ b/spec/stubs.coffee @@ -0,0 +1,16 @@ +Logger = require '../lib/logger' +Opener = require '../lib/opener' + +class NullLogger extends Logger + error: -> null + warning: -> null + info: -> null + + +class NullOpener extends Opener + open: (filePath, texPath, lineNumber, callback) -> null + + +module.exports = + Logger: NullLogger + Opener: NullOpener