@@ -369,6 +369,7 @@ pub struct Protocols {
369369 pub protocols : Vec < Protocol > ,
370370 pub unmocked_commands : Vec < PathBuf > ,
371371 pub interpreter : Option < PathBuf > ,
372+ pub mocked_executables : Vec < PathBuf > ,
372373}
373374
374375impl Protocols {
@@ -377,6 +378,7 @@ impl Protocols {
377378 protocols,
378379 unmocked_commands : vec ! [ ] ,
379380 interpreter : None ,
381+ mocked_executables : vec ! [ ] ,
380382 }
381383 }
382384
@@ -405,6 +407,16 @@ impl Protocols {
405407 Ok ( ( ) )
406408 }
407409
410+ fn add_mocked_executables ( & mut self , object : & Hash ) -> R < ( ) > {
411+ if let Ok ( mocked_executables) = object. expect_field ( "mockedExecutables" ) {
412+ for mocked_executable in mocked_executables. expect_array ( ) ? {
413+ self . mocked_executables
414+ . push ( PathBuf :: from ( mocked_executable. expect_str ( ) ?) ) ;
415+ }
416+ }
417+ Ok ( ( ) )
418+ }
419+
408420 fn parse ( yaml : Yaml ) -> R < Protocols > {
409421 Ok ( match & yaml {
410422 Yaml :: Array ( array) => Protocols :: from_array ( & array) ?,
@@ -413,10 +425,19 @@ impl Protocols {
413425 object. expect_field ( "protocol" ) ,
414426 ) {
415427 ( Ok ( protocols) , _) => {
416- check_keys ( & [ "protocols" , "interpreter" , "unmockedCommands" ] , object) ?;
428+ check_keys (
429+ & [
430+ "protocols" ,
431+ "interpreter" ,
432+ "unmockedCommands" ,
433+ "mockedExecutables" ,
434+ ] ,
435+ object,
436+ ) ?;
417437 let mut protocols = Protocols :: from_array ( protocols. expect_array ( ) ?) ?;
418438 protocols. add_unmocked_commands ( object) ?;
419439 protocols. add_interpreter ( object) ?;
440+ protocols. add_mocked_executables ( object) ?;
420441 protocols
421442 }
422443 ( Err ( _) , Ok ( _) ) => Protocols :: new ( vec ! [ Protocol :: from_object( & object) ?] ) ,
@@ -559,7 +580,8 @@ mod load {
559580 format!(
560581 "error in {}.protocols.yaml: \
561582 unexpected field 'foo', \
562- possible values: 'protocols', 'interpreter', 'unmockedCommands'",
583+ possible values: 'protocols', 'interpreter', 'unmockedCommands', \
584+ 'mockedExecutables'",
563585 path_to_string( & tempfile. path( ) ) ?
564586 )
565587 ) ;
@@ -999,7 +1021,27 @@ mod load {
9991021 ) ?
10001022 . mocked_files
10011023 . map( |path| path. to_string_lossy( ) . to_string( ) ) ,
1002- vec![ ( "/foo" ) ]
1024+ vec![ "/foo" ]
1025+ ) ;
1026+ Ok ( ( ) )
1027+ }
1028+
1029+ #[ test]
1030+ fn allows_to_specify_mocked_executables ( ) -> R < ( ) > {
1031+ let tempfile = TempFile :: new ( ) ?;
1032+ assert_eq ! (
1033+ test_parse(
1034+ & tempfile,
1035+ r"
1036+ |protocols:
1037+ | - protocol: []
1038+ |mockedExecutables:
1039+ | - foo
1040+ "
1041+ ) ?
1042+ . mocked_executables
1043+ . map( |path| path. to_string_lossy( ) . to_string( ) ) ,
1044+ vec![ "foo" ]
10031045 ) ;
10041046 Ok ( ( ) )
10051047 }
0 commit comments