11/* jshint expr: true */
22var chai = require ( 'chai' ) ;
3+ var logger = require ( 'winston' ) ;
34var sinon = require ( 'sinon' ) ;
45var sinonChai = require ( 'sinon-chai' ) ;
56var createBots = require ( '../lib/helpers' ) . createBots ;
67var Bot = require ( '../lib/bot' ) ;
78var ConfigurationError = require ( '../lib/errors' ) . ConfigurationError ;
9+ var index = require ( '../index' ) ;
10+ var testConfig = require ( './fixtures/test-config.json' ) ;
11+ var singleTestConfig = require ( './fixtures/single-test-config.json' ) ;
12+ var badConfig = require ( './fixtures/bad-config.json' ) ;
13+ var stringConfig = require ( './fixtures/string-config.json' ) ;
814
915chai . should ( ) ;
1016chai . use ( sinonChai ) ;
@@ -13,43 +19,43 @@ describe('Create Bots', function() {
1319 before ( function ( ) {
1420 this . connectStub = sinon . stub ( ) ;
1521 Bot . prototype . connect = this . connectStub ;
16- process . env . CONFIG_FILE = process . cwd ( ) + '/test/fixtures/test-config.json' ;
1722 } ) ;
1823
1924 afterEach ( function ( ) {
2025 this . connectStub . reset ( ) ;
2126 } ) ;
2227
2328 it ( 'should work when given an array of configs' , function ( ) {
24- process . env . CONFIG_FILE = process . cwd ( ) + '/test/fixtures/test-config.json' ;
25- var bots = createBots ( ) ;
29+ var bots = createBots ( testConfig ) ;
2630 bots . length . should . equal ( 2 ) ;
2731 this . connectStub . should . have . been . called ;
2832 } ) ;
2933
3034 it ( 'should work when given an object as a config file' , function ( ) {
31- process . env . CONFIG_FILE = process . cwd ( ) + '/test/fixtures/single-test-config.json' ;
32- var bots = createBots ( ) ;
35+ var bots = createBots ( singleTestConfig ) ;
3336 bots . length . should . equal ( 1 ) ;
3437 this . connectStub . should . have . been . called ;
3538 } ) ;
3639
3740 it ( 'should throw a configuration error if any fields are missing' , function ( ) {
38- process . env . CONFIG_FILE = process . cwd ( ) + '/test/fixtures/bad-config.json' ;
3941 function wrap ( ) {
40- createBots ( ) ;
42+ createBots ( badConfig ) ;
4143 }
4244
4345 ( wrap ) . should . throw ( ConfigurationError , 'Missing configuration field nickname' ) ;
4446 } ) ;
4547
4648 it ( 'should throw if a configuration file is neither an object or an array' , function ( ) {
47- process . env . CONFIG_FILE = process . cwd ( ) + '/test/fixtures/string-config.json' ;
48-
4949 function wrap ( ) {
50- createBots ( ) ;
50+ createBots ( stringConfig ) ;
5151 }
5252
5353 ( wrap ) . should . throw ( ConfigurationError ) ;
5454 } ) ;
55+
56+ it ( 'should be possible to run it through require(\'slack-irc\')' , function ( ) {
57+ var bots = index ( singleTestConfig ) ;
58+ bots . length . should . equal ( 1 ) ;
59+ this . connectStub . should . have . been . called ;
60+ } ) ;
5561} ) ;
0 commit comments