@@ -27,15 +27,18 @@ use rust_arkitect::dsl::{ArchitecturalRules, Arkitect, Project};
2727fn test_architectural_rules () {
2828 let project = Project :: new ();
2929
30+ #[rustfmt:: skip]
3031 let rules = ArchitecturalRules :: define ()
31- . component (" Domain" )
32- . located_at (" my_project::domain" )
33- . allow_external_dependencies (& [" std::fmt" ])
32+ . rules_for_module (" sample_project::application" )
33+ . allow_dependencies_on (& [" sample_project::domain" ])
34+
35+ . rules_for_module (" sample_project::domain" )
3436 . must_not_depend_on_anything ()
35- . component (" Application" )
36- . located_at (" my_project::application" )
37- . may_depend_on (& [" Domain" ])
38- . finalize ();
37+
38+ . rules_for_module (" sample_project::infrastructure" )
39+ . allow_dependencies_on (& [" sample_project::domain" , " sample_project::application" ])
40+
41+ . build ();
3942
4043 let result = Arkitect :: ensure_that (project ). complies_with (rules );
4144
@@ -72,25 +75,23 @@ You can define and test architectural rules:
7275fn test_architecture_baseline () {
7376 let project = Project :: new ();
7477
78+ #[rustfmt:: skip]
7579 let rules = ArchitecturalRules :: define ()
76- . component (" Application" )
77- . located_at (" my_project::application" )
78- . may_depend_on (& [" Domain" ])
80+ . rules_for_crate (" application" )
81+ . allow_dependencies_on (& [" domain" ])
7982
80- . component (" Domain" )
81- . located_at (" my_project::domain" )
82- . allow_external_dependencies (& [" std::fmt" ])
83+ . rules_for_module (" domain" )
8384 . must_not_depend_on_anything ()
8485
85- . component (" Infrastructure" )
86- . located_at (" my_project::infrastructure" )
87- . allow_external_dependencies (& [" serde" ])
88- . may_depend_on (& [" Domain" , " Application" ])
86+ . rules_for_module (" infrastructure" )
87+ . allow_dependencies_on (& [" domain" , " application" ])
8988
90- . finalize ();
89+ . build ();
9190
9291 let baseline_violations = 30 ;
93- let result = Arkitect :: ensure_that (project ). with_baseline (baseline_violations ). complies_with (rules );
92+ let result = Arkitect :: ensure_that (project )
93+ . with_baseline (baseline_violations )
94+ . complies_with (rules );
9495
9596 assert! (
9697 result . is_ok (),
@@ -134,11 +135,6 @@ Example Output:
134135Rust Arkitect allows you to create custom rules to test your project's architecture. These rules can be implemented by creating a struct and implementing the ` Rule ` trait for it. Below is an example of how to define and use a custom rule in a test:
135136
136137``` rust
137- use rust_arkitect :: dsl :: Arkitect ;
138- use rust_arkitect :: dsl :: Project ;
139- use rust_arkitect :: rules :: Rule ;
140- use std :: fmt :: {Display , Formatter };
141-
142138// Define a custom rule
143139struct TestRule ;
144140
@@ -172,7 +168,7 @@ fn test_custom_rule_execution() {
172168 let project = Project :: new ();
173169
174170 // Create a new instance of the custom rule
175- let rule = Box :: new (TestRule :: new (" my_crate" , & [" a:crate ::a_module" ]));
171+ let rule = Box :: new (TestRule :: new (" my_crate" , & [" another_crate ::a_module" ]));
176172
177173 // Apply the rule to the project
178174 let result = Arkitect :: ensure_that (project ). complies_with (vec! [rule ]);
0 commit comments