@@ -7,66 +7,56 @@ const {expect} = chai;
7
7
chai . use ( sinonChai ) ;
8
8
9
9
describe ( `prompter` , ( ) => {
10
- let inquirer , commit , prompter ;
11
- beforeEach ( ( ) => {
12
- inquirer = { prompt : sinon . spy ( ) } ;
10
+ let inquirer , commit , prompter , commitAnswers ;
11
+
12
+ before ( ( ) => {
13
13
commit = sinon . spy ( ) ;
14
+ inquirer = { prompt : sinon . spy ( ) } ;
14
15
prompter = proxyquire ( './' , { inquirer} ) . prompter ;
15
16
} ) ;
16
17
17
- it ( `call inquirer.prompt` , ( ) => {
18
- prompter ( inquirer ) ;
19
- expect ( inquirer . prompt ) . to . have . been . calledWith ( sinon . match . array , sinon . match . func ) ;
18
+ beforeEach ( ( ) => {
19
+ prompter ( null , commit ) ;
20
+ commitAnswers = inquirer . prompt . getCall ( 0 ) . args [ 1 ] ;
20
21
} ) ;
21
22
22
- describe ( `commitAnswers` , ( ) => {
23
- let commitAnswers ;
24
- beforeEach ( ( ) => {
25
- prompter ( inquirer , commit ) ;
26
- commitAnswers = inquirer . prompt . getCall ( 0 ) . args [ 1 ] ;
27
- } ) ;
23
+ it ( `should call commit with the proper message` , ( ) => {
24
+ const message = 'sample commit message' ;
25
+ const issues = 'CZ-234 CZ-235' ;
26
+ const workflow = 'closed' ;
27
+ const time = '3y 2w 7d 8h 30m' ;
28
+ const comment = 'This took waaaaay too long' ;
29
+ commitAnswers ( { message, issues, workflow, time, comment} ) ;
30
+ expect ( commit ) . to . have . been . calledWith ( [
31
+ message ,
32
+ issues ,
33
+ `#${ workflow } ` ,
34
+ `#time ${ time } ` ,
35
+ `#comment ${ comment } `
36
+ ] . join ( ' ' ) ) ;
37
+ } ) ;
28
38
29
- it ( `should call commit with the proper message` , ( ) => {
39
+ [ 'workflow' , 'time' , 'comment' ] . forEach ( ( item ) => {
40
+ it ( `should just leave off ${ item } if it's not specified` , ( ) => {
30
41
const message = 'sample commit message' ;
31
42
const issues = 'CZ-234 CZ-235' ;
32
43
const workflow = 'closed' ;
33
44
const time = '3y 2w 7d 8h 30m' ;
34
45
const comment = 'This took waaaaay too long' ;
35
- commitAnswers ( { message, issues, workflow, time, comment} ) ;
36
- expect ( commit ) . to . have . been . calledWith ( [
46
+ const answers = { message, issues, workflow, time, comment} ;
47
+ delete answers [ item ] ;
48
+ commitAnswers ( answers ) ;
49
+ expect ( commit ) . to . have . been . calledWith ( filter ( [
37
50
message ,
38
51
issues ,
39
- `#${ workflow } ` ,
40
- `#time ${ time } ` ,
41
- `#comment ${ comment } `
42
- ] . join ( ' ' ) ) ;
52
+ item !== 'workflow' ? `#${ workflow } ` : undefined ,
53
+ item !== 'time' ? `#time ${ time } ` : undefined ,
54
+ item !== 'comment' ? `#comment ${ comment } ` : undefined
55
+ ] ) . join ( ' ' ) ) ;
43
56
} ) ;
44
-
45
- [ 'workflow' , 'time' , 'comment' ] . forEach ( ( item ) => {
46
- it ( `should just leave off ${ item } if it's not specified` , ( ) => {
47
- const message = 'sample commit message' ;
48
- const issues = 'CZ-234 CZ-235' ;
49
- const workflow = 'closed' ;
50
- const time = '3y 2w 7d 8h 30m' ;
51
- const comment = 'This took waaaaay too long' ;
52
- const answers = { message, issues, workflow, time, comment} ;
53
- delete answers [ item ] ;
54
- commitAnswers ( answers ) ;
55
- expect ( commit ) . to . have . been . calledWith ( filter ( [
56
- message ,
57
- issues ,
58
- item !== 'workflow' ? `#${ workflow } ` : undefined ,
59
- item !== 'time' ? `#time ${ time } ` : undefined ,
60
- item !== 'comment' ? `#comment ${ comment } ` : undefined
61
- ] ) . join ( ' ' ) ) ;
62
- } ) ;
63
- } )
64
57
} ) ;
65
-
66
58
} ) ;
67
59
68
60
function filter ( array ) {
69
- return array . filter ( function ( item ) {
70
- return ! ! item ;
71
- } ) ;
61
+ return array . filter ( Boolean ) ;
72
62
}
0 commit comments