@@ -15,20 +15,41 @@ describe("init", () => {
1515 let args = testObjects . initSampleArgs ;
1616 var sandbox ;
1717
18- before ( ( ) => {
18+ beforeEach ( ( ) => {
1919 sandbox = sinon . createSandbox ( ) ;
2020 sendUsageReportStub = sandbox . stub ( ) . callsFake ( function ( ) {
2121 return "end" ;
2222 } ) ;
2323 } ) ;
2424
25- after ( ( ) => {
25+ afterEach ( ( ) => {
2626 sandbox . restore ( ) ;
2727 sinon . restore ( ) ;
2828 } ) ;
2929
3030 describe ( "init" , ( ) => {
31+ it ( "fail if given path is not present" , ( ) => {
32+ dirExistsStub = sandbox . stub ( ) . yields ( false ) ;
33+ writeStub = sandbox . stub ( ) ;
34+
35+ const init = proxyquire ( "../../../../bin/commands/init" , {
36+ "../helpers/utils" : {
37+ sendUsageReport : sendUsageReportStub ,
38+ } ,
39+ "../helpers/fileHelpers" : {
40+ dirExists : dirExistsStub ,
41+ write : writeStub ,
42+ } ,
43+ } ) ;
44+
45+ init ( args ) ;
46+ sinon . assert . calledOnce ( dirExistsStub ) ;
47+ sinon . assert . notCalled ( writeStub ) ;
48+ sinon . assert . calledOnceWithExactly ( sendUsageReportStub , null , args , Constants . userMessages . DIR_NOT_FOUND , Constants . messageTypes . ERROR , 'path_to_init_not_found' ) ;
49+ } ) ;
50+
3151 it ( "fail if browserstack.json is already present" , ( ) => {
52+ dirExistsStub = sandbox . stub ( ) . yields ( true ) ;
3253 fileExistsStub = sandbox . stub ( ) . yields ( true ) ;
3354 writeStub = sandbox . stub ( ) ;
3455
@@ -37,18 +58,21 @@ describe("init", () => {
3758 sendUsageReport : sendUsageReportStub ,
3859 } ,
3960 "../helpers/fileHelpers" : {
61+ dirExists : dirExistsStub ,
4062 fileExists : fileExistsStub ,
4163 write : writeStub ,
4264 } ,
4365 } ) ;
4466
4567 init ( args ) ;
68+ sinon . assert . calledOnce ( dirExistsStub ) ;
4669 sinon . assert . calledOnce ( fileExistsStub ) ;
4770 sinon . assert . notCalled ( writeStub ) ;
4871 sinon . assert . calledOnceWithExactly ( sendUsageReportStub , null , args , Constants . userMessages . CONFIG_FILE_EXISTS , Constants . messageTypes . ERROR , 'bstack_json_already_exists' ) ;
4972 } ) ;
5073
5174 it ( "create browserstack.json if not already present" , ( ) => {
75+ dirExistsStub = sandbox . stub ( ) . yields ( true ) ;
5276 fileExistsStub = sandbox . stub ( ) . yields ( false ) ;
5377 writeStub = sandbox . stub ( ) ;
5478
@@ -57,12 +81,14 @@ describe("init", () => {
5781 sendUsageReport : sendUsageReportStub ,
5882 } ,
5983 "../helpers/fileHelpers" : {
84+ dirExists : dirExistsStub ,
6085 fileExists : fileExistsStub ,
6186 write : writeStub ,
6287 } ,
6388 } ) ;
6489
6590 init ( args ) ;
91+ sinon . assert . calledOnce ( dirExistsStub ) ;
6692 sinon . assert . calledOnce ( fileExistsStub ) ;
6793 sinon . assert . calledOnce ( writeStub ) ;
6894 } ) ;
0 commit comments