<commit_before>var reut = require("reut")
  , RoilApp = require("../src/app")
  , WebResource = require("../src/resource")
  , EventEmitter = require("events").EventEmitter

reut.suite("App class")
.setup(function(f) {
  f.conf = {
    port: 8913
  , plugIns: []
  }
  f.app = new RoilApp(f.conf)
})
.teardown(function(f) {
  WebResource.instances = {}
})
.test("run and shutdown methods", function(t, f) {
  var app = f.app
    , server = app.server
  app.run()
  t.ok(server)
  t.typeOf(server.use, 'function')
  app.shutdown()
})
.test("loadPlugin", function(t, f) {
  var app = f.app
    , dummyPlugin = t.called(function(roil) {
        t.is(roil, app)
      })
  app.loadPlugin(dummyPlugin)
})
.test("addResource then matchResource", function(t, f) {
  var app = f.app
    , someResource = WebResource.new('/foo/bar')
  app.addResource(someResource)
  app.matchResource(WebResource, t.cb(function(r) {
    t.is(r, someResource)
  }))
})
.test("matchResource then addResource", function(t, f) {
  var app = f.app
    , anotherRes
  app.matchResource(WebResource, t.cb(function(r) {
    t.is(r, anotherRes)
  }))
  anotherRes = WebResource.new("/holy/crap")
  app.addResource(anotherRes)
})
.test("Exposing resource classes", function(t, f) {
  var r = f.app.resource
  t.typeOf(r.File, 'function')
  t.typeOf(r.WebResource, 'function')
})
.test("addResource more than once", function(t, f) {
  var app = f.app
    , r = app.resource
    , someResource = WebResource.new('/foo/bar')
    , count = 0
  app.matchResource(r.WebResource, function(r) {
    count++
  })
  app.addResource(someResource)
  app.addResource(someResource)
  app.addResource(someResource)
  t.is(count, 1)
})
.test("attachWorkspace()", function(t, f) {
  var app = f.app
    , ws = new EventEmitter
    , blah = {}
  app.addResource = t.cb(function(r) {
    t.is(r, blah)
  })
  app.attachWorkspace(ws)
  ws.emit("BC:resource", blah)
})<commit_msg>Extract setup for app test<commit_after>var reut = require("reut")
  , RoilApp = require("../src/app")
  , WebResource = require("../src/resource")
  , EventEmitter = require("events").EventEmitter

reut.suite("App class")
.setup(setupApp)
.teardown(function(f) {
  WebResource.instances = {}
})
.test("run and shutdown methods", function(t, f) {
  var app = f.app
    , server = app.server
  app.run()
  t.ok(server)
  t.typeOf(server.use, 'function')
  app.shutdown()
})
.test("loadPlugin", function(t, f) {
  var app = f.app
    , dummyPlugin = t.called(function(roil) {
        t.is(roil, app)
      })
  app.loadPlugin(dummyPlugin)
})
.test("addResource then matchResource", function(t, f) {
  var app = f.app
    , someResource = WebResource.new('/foo/bar')
  app.addResource(someResource)
  app.matchResource(WebResource, t.cb(function(r) {
    t.is(r, someResource)
  }))
})
.test("matchResource then addResource", function(t, f) {
  var app = f.app
    , anotherRes
  app.matchResource(WebResource, t.cb(function(r) {
    t.is(r, anotherRes)
  }))
  anotherRes = WebResource.new("/holy/crap")
  app.addResource(anotherRes)
})
.test("Exposing resource classes", function(t, f) {
  var r = f.app.resource
  t.typeOf(r.File, 'function')
  t.typeOf(r.WebResource, 'function')
})
.test("addResource more than once", function(t, f) {
  var app = f.app
    , r = app.resource
    , someResource = WebResource.new('/foo/bar')
    , count = 0
  app.matchResource(r.WebResource, function(r) {
    count++
  })
  app.addResource(someResource)
  app.addResource(someResource)
  app.addResource(someResource)
  t.is(count, 1)
})
.test("attachWorkspace()", function(t, f) {
  var app = f.app
    , ws = new EventEmitter
    , blah = {}
  app.addResource = t.cb(function(r) {
    t.is(r, blah)
  })
  app.attachWorkspace(ws)
  ws.emit("BC:resource", blah)
})

function setupApp(f) {
  f.conf = {
    port: 8913
  , plugIns: []
  }
  f.app = new RoilApp(f.conf)
}
{'fraction_non_alphanumeric': 0.1731958762886598, 'fraction_numerical': 0.003092783505154639, 'mean_word_length': 3.5551643192488265, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5027774', 'n_tokens_mistral': 1464, 'n_tokens_neox': 1446, 'n_words': 268}