@@ -23,6 +23,10 @@ impl Rule for Scope {
2323 const LEVEL : Level = Level :: Error ;
2424
2525 fn message ( & self , message : & Message ) -> String {
26+ if self . options . len ( ) == 0 {
27+ return "scopes are not allowed" . to_string ( ) ;
28+ }
29+
2630 format ! (
2731 "scope {} is not allowed. Only {:?} are allowed" ,
2832 message. scope. as_ref( ) . unwrap_or( & "" . to_string( ) ) ,
@@ -59,44 +63,45 @@ mod tests {
5963 use super :: * ;
6064
6165 #[ test]
62- fn test_valid_scope ( ) {
66+ fn test_empty_scope ( ) {
6367 let mut rule = Scope :: default ( ) ;
6468 rule. options = vec ! [ "api" . to_string( ) , "web" . to_string( ) ] ;
6569
6670 let message = Message {
6771 body : None ,
6872 description : None ,
6973 footers : None ,
70- r#type : Some ( "feat" . to_string ( ) ) ,
71- raw : "feat(web): broadcast $destroy event on scope destruction " . to_string ( ) ,
72- scope : Some ( "web" . to_string ( ) ) ,
74+ r#type : None ,
75+ raw : "" . to_string ( ) ,
76+ scope : None ,
7377 subject : None ,
7478 } ;
7579
76- assert ! ( rule. validate( & message) . is_none( ) ) ;
80+ let violation = rule. validate ( & message) ;
81+ assert ! ( violation. is_some( ) ) ;
82+ assert_eq ! ( violation. clone( ) . unwrap( ) . level, Level :: Error ) ;
83+ assert_eq ! (
84+ violation. unwrap( ) . message,
85+ "scope is not allowed. Only [\" api\" , \" web\" ] are allowed"
86+ ) ;
7787 }
7888
7989 #[ test]
80- fn test_empty_message ( ) {
81- let rule = Scope :: default ( ) ;
90+ fn test_valid_scope ( ) {
91+ let mut rule = Scope :: default ( ) ;
92+ rule. options = vec ! [ "api" . to_string( ) , "web" . to_string( ) ] ;
8293
8394 let message = Message {
8495 body : None ,
8596 description : None ,
8697 footers : None ,
87- r#type : None ,
88- raw : "" . to_string ( ) ,
89- scope : None ,
98+ r#type : Some ( "feat" . to_string ( ) ) ,
99+ raw : "feat(web): broadcast $destroy event on scope destruction " . to_string ( ) ,
100+ scope : Some ( "web" . to_string ( ) ) ,
90101 subject : None ,
91102 } ;
92103
93- let violation = rule. validate ( & message) ;
94- assert ! ( violation. is_some( ) ) ;
95- assert_eq ! ( violation. clone( ) . unwrap( ) . level, Level :: Error ) ;
96- assert_eq ! (
97- violation. unwrap( ) . message,
98- "scope is not allowed. Only [] are allowed"
99- ) ;
104+ assert ! ( rule. validate( & message) . is_none( ) ) ;
100105 }
101106
102107 #[ test]
@@ -142,7 +147,7 @@ mod tests {
142147 assert_eq ! ( violation. clone( ) . unwrap( ) . level, Level :: Error ) ;
143148 assert_eq ! (
144149 violation. unwrap( ) . message,
145- "scope invalid is not allowed. Only [] are allowed" . to_string( )
150+ "scopes are not allowed" . to_string( )
146151 ) ;
147152 }
148153}
0 commit comments