Skip to content
This repository has been archived by the owner on Aug 14, 2022. It is now read-only.

Commit

Permalink
Fix and improve specs related to bootstrapping
Browse files Browse the repository at this point in the history
First and foremost fixes specs related to `Latex` and bootstrapping
the global `window.latex` instance.
  • Loading branch information
thomasjo committed Apr 10, 2015
1 parent ef28a25 commit b0e5924
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 24 deletions.
25 changes: 15 additions & 10 deletions spec/latex-spec.coffee
Original file line number Diff line number Diff line change
@@ -1,47 +1,52 @@
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()
expect(latex.opener).toBeDefined()

describe "setDefaultBuilder", ->
it "sets the default builder to LatexmkBuilder", ->
origin = latex.builder
origin = latex.__builder
latex.setDefaultBuilder()

expect(origin).toBeUndefined()
expect(latex.builder.constructor.name).toBe 'LatexmkBuilder'

describe "setDefaultLogger", ->
it "sets the default logger to ConsoleLogger", ->
origin = latex.logger
origin = latex.__logger
latex.setDefaultLogger()

expect(origin).toBeUndefined()
expect(latex.logger.constructor.name).toBe 'ConsoleLogger'

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] = []
Expand Down
9 changes: 2 additions & 7 deletions spec/spec-bootstrap.coffee
Original file line number Diff line number Diff line change
@@ -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())
8 changes: 1 addition & 7 deletions spec/spec-helpers.coffee
Original file line number Diff line number Diff line change
@@ -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: ->
Expand All @@ -30,5 +26,3 @@ module.exports =
originalInterval = env.defaultTimeoutInterval
env.defaultTimeoutInterval = interval
originalInterval

nullOpener: -> new NullOpener()
16 changes: 16 additions & 0 deletions spec/stubs.coffee
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b0e5924

Please sign in to comment.