@@ -9,16 +9,16 @@ describe("The 'select' method", function () {
9
9
10
10
var rp ;
11
11
before ( function ( done ) {
12
- RedisProcess . start ( function ( err , _rp ) {
13
- rp = _rp ;
14
- return done ( err ) ;
15
- } ) ;
12
+ RedisProcess . start ( function ( err , _rp ) {
13
+ rp = _rp ;
14
+ return done ( err ) ;
15
+ } ) ;
16
16
} )
17
17
18
18
function removeMochaListener ( ) {
19
- var mochaListener = process . listeners ( 'uncaughtException' ) . pop ( ) ;
20
- process . removeListener ( 'uncaughtException' , mochaListener ) ;
21
- return mochaListener ;
19
+ var mochaListener = process . listeners ( 'uncaughtException' ) . pop ( ) ;
20
+ process . removeListener ( 'uncaughtException' , mochaListener ) ;
21
+ return mochaListener ;
22
22
}
23
23
24
24
function allTests ( parser , ip ) {
@@ -32,10 +32,10 @@ describe("The 'select' method", function () {
32
32
client = redis . createClient . apply ( redis . createClient , args ) ;
33
33
client . once ( "error" , done ) ;
34
34
client . once ( "connect" , function ( ) {
35
- client . quit ( ) ;
35
+ client . quit ( ) ;
36
36
} ) ;
37
37
client . on ( 'end' , function ( ) {
38
- return done ( ) ;
38
+ return done ( ) ;
39
39
} ) ;
40
40
} ) ;
41
41
@@ -70,15 +70,14 @@ describe("The 'select' method", function () {
70
70
} ) ;
71
71
} ) ;
72
72
73
- describe ( "and no callback is specified" , function ( ) {
73
+ describe ( "and a callback is specified" , function ( ) {
74
74
describe ( "with a valid db index" , function ( ) {
75
75
it ( "selects the appropriate database" , function ( done ) {
76
76
assert . strictEqual ( client . selected_db , null , "default db should be null" ) ;
77
- client . select ( 1 ) ;
78
- setTimeout ( function ( ) {
77
+ client . select ( 1 , function ( ) {
79
78
assert . equal ( client . selected_db , 1 , "we should have selected the new valid DB" ) ;
80
79
return done ( ) ;
81
- } , 100 ) ;
80
+ } ) ;
82
81
} ) ;
83
82
} ) ;
84
83
@@ -90,15 +89,30 @@ describe("The 'select' method", function () {
90
89
return done ( ) ;
91
90
} ) ;
92
91
} ) ;
92
+ } ) ;
93
+ } ) ;
94
+
95
+ describe ( "and no callback is specified" , function ( ) {
96
+ describe ( "with a valid db index" , function ( ) {
97
+ it ( "selects the appropriate database" , function ( done ) {
98
+ assert . strictEqual ( client . selected_db , null , "default db should be null" ) ;
99
+ client . select ( 1 ) ;
100
+ setTimeout ( function ( ) {
101
+ assert . equal ( client . selected_db , 1 , "we should have selected the new valid DB" ) ;
102
+ return done ( ) ;
103
+ } , 100 ) ;
104
+ } ) ;
105
+ } ) ;
93
106
107
+ describe ( "with an invalid db index" , function ( ) {
94
108
it ( "throws an error when callback not provided" , function ( done ) {
95
109
var mochaListener = removeMochaListener ( ) ;
96
110
assert . strictEqual ( client . selected_db , null , "default db should be null" ) ;
97
111
98
112
process . once ( 'uncaughtException' , function ( err ) {
99
- process . on ( 'uncaughtException' , mochaListener ) ;
100
- assert . equal ( err . message , 'ERR invalid DB index' ) ;
101
- return done ( ) ;
113
+ process . on ( 'uncaughtException' , mochaListener ) ;
114
+ assert . equal ( err . message , 'ERR invalid DB index' ) ;
115
+ return done ( ) ;
102
116
} ) ;
103
117
104
118
client . select ( 9999 ) ;
0 commit comments