11use std:: error:: Error ;
22
3+ use crate :: assert_error;
34use crate :: auth_monitor_options:: AuthMonitorOptions ;
45use crate :: auth_monitor_params:: {
56 AuthMonitorParams , MAX_FAILED_ATTEMPTS_OPTION , RESET_AFTER_SECONDS_OPTION ,
@@ -16,14 +17,7 @@ fn when_parsing_no_arguments_then_return_file_not_specified_error() {
1617}
1718
1819fn expect_file_not_specified_error ( result : AuthMonitorResult ) {
19- expect_error ( result, "File path not specified" ) ;
20- }
21-
22- fn expect_error ( result : AuthMonitorResult , expected : & str ) {
23- match result {
24- Ok ( _) => panic ! ( "Error \" {}\" was expected" , expected) ,
25- Err ( error) => assert_eq ! ( error. to_string( ) , expected) ,
26- }
20+ assert_error ! ( result, "File path not specified" ) ;
2721}
2822
2923#[ test]
@@ -61,7 +55,7 @@ fn when_parsing_filepath_passed_more_than_once_then_return_file_path_specified_m
6155}
6256
6357fn expect_file_path_specified_more_than_once_error ( result : AuthMonitorResult ) {
64- expect_error ( result, "File path specified more than once" ) ;
58+ assert_error ! ( result, "File path specified more than once" ) ;
6559}
6660
6761#[ test]
@@ -123,7 +117,7 @@ fn when_parsing_option_without_value_then_return_missing_option_value_error() {
123117 for option_argument in option_arguments {
124118 let arguments = [ String :: from ( FILEPATH ) , option_argument] ;
125119 let expected = format ! ( "Missing value for option --{}" , option) ;
126- expect_error ( AuthMonitorParams :: from_arguments ( & arguments) , & expected) ;
120+ assert_error ! ( AuthMonitorParams :: from_arguments( & arguments) , expected) ;
127121 }
128122 }
129123}
@@ -136,7 +130,7 @@ fn when_parsing_option_with_invalid_value_then_return_invalid_option_value_error
136130 let option_argument = format ! ( "--{}={}" , option, value) ;
137131 let arguments = [ String :: from ( FILEPATH ) , option_argument] ;
138132 let expected = format ! ( "\" {}\" is not a valid value for option --{}" , value, option) ;
139- expect_error ( AuthMonitorParams :: from_arguments ( & arguments) , & expected) ;
133+ assert_error ! ( AuthMonitorParams :: from_arguments( & arguments) , expected) ;
140134 }
141135 }
142136}
@@ -147,7 +141,7 @@ fn when_parsing_option_with_no_value_then_return_no_value_error() {
147141 let option_argument = format ! ( "--{}=" , option) ;
148142 let arguments = [ String :: from ( FILEPATH ) , option_argument] ;
149143 let expected = format ! ( "Missing value for option --{}" , option) ;
150- expect_error ( AuthMonitorParams :: from_arguments ( & arguments) , & expected) ;
144+ assert_error ! ( AuthMonitorParams :: from_arguments( & arguments) , expected) ;
151145 }
152146}
153147
@@ -159,7 +153,7 @@ fn when_parsing_option_with_value_less_than_0_then_invalid_value_error() {
159153 let option_argument = format ! ( "--{}={}" , option, value) ;
160154 let arguments = [ String :: from ( FILEPATH ) , option_argument] ;
161155 let expected = format ! ( "{} must be greater than 0" , option) ;
162- expect_error ( AuthMonitorParams :: from_arguments ( & arguments) , & expected) ;
156+ assert_error ! ( AuthMonitorParams :: from_arguments( & arguments) , expected) ;
163157 }
164158 }
165159}
@@ -193,6 +187,6 @@ fn when_parsing_unknown_option_then_return_unknown_option_error() {
193187 ] {
194188 let arguments = [ String :: from ( FILEPATH ) , String :: from ( option) ] ;
195189 let expected = format ! ( "Unknown option {}" , option) ;
196- expect_error ( AuthMonitorParams :: from_arguments ( & arguments) , & expected)
190+ assert_error ! ( AuthMonitorParams :: from_arguments( & arguments) , expected)
197191 }
198192}
0 commit comments