@@ -9,55 +9,67 @@ class Test
99 @helper = Test . new
1010 end
1111
12- describe "#components " do
13- it "extracts components from components/_index.scss " do
12+ shared_examples "a sass import extractor " do | method , file |
13+ it "extracts names via @import " do
1414 allow ( File ) . to receive ( :readlines ) . and_return <<~FILE . split ( "\n " )
1515 @import "../base";
1616
17- @import "first-component/index";
18- @import "second-component/index";
19- @import "third-component/index";
17+ @import "first";
18+ @import "second/index";
19+ @import "th-ird/_index";
20+ @import "fourth/index.scss";
21+ @import 'fifth/_index.scss';
22+ // @import "false-match/index";
23+ @import "";
2024 FILE
2125
22- expect ( @helper . components ) . to eq ( %w[
23- first-component
24- second-component
25- third-component
26+ expect ( @helper . send ( method ) ) . to eq ( %w[
27+ first
28+ second
29+ th-ird
30+ fourth
31+ fifth
2632 ] )
2733 end
2834
29- it "throws if no components are found in components/_index.scss" do
30- allow ( File ) . to receive ( :readlines ) . and_return [ ]
31-
32- expect { @helper . components } . to raise_error (
33- "No matches found in components/_index.scss" ,
34- )
35- end
36- end
37-
38- describe "#overrides" do
39- it "extracts overrides from overrides/_index.scss" do
35+ it "extracts names via @use" do
4036 allow ( File ) . to receive ( :readlines ) . and_return <<~FILE . split ( "\n " )
41- @import "../a-dependency ";
37+ @use "../base ";
4238
43- @import "one";
44- @import "two";
45- @import "th-ree";
39+ @use "first";
40+ @use "second/index";
41+ @use "th-ird/_index";
42+ @use "fourth/index.scss";
43+ @use 'fifth/_index.scss';
44+ @use "sixth" with ($config: true);
45+ // @use "false-match/index";
46+ @use "";
4647 FILE
4748
48- expect ( @helper . overrides ) . to eq ( %w[
49- one
50- two
51- th-ree
49+ expect ( @helper . send ( method ) ) . to eq ( %w[
50+ first
51+ second
52+ th-ird
53+ fourth
54+ fifth
55+ sixth
5256 ] )
5357 end
5458
55- it "throws if no overrides are found in components/_index.scss " do
59+ it "throws if no matches are found" do
5660 allow ( File ) . to receive ( :readlines ) . and_return [ ]
5761
58- expect { @helper . overrides } . to raise_error (
59- "No matches found in overrides/_index.scss " ,
62+ expect { @helper . send ( method ) } . to raise_error (
63+ "No matches found in #{ file } " ,
6064 )
6165 end
6266 end
67+
68+ describe "#components" do
69+ it_behaves_like "a sass import extractor" , :components , "components/_index.scss"
70+ end
71+
72+ describe "#overrides" do
73+ it_behaves_like "a sass import extractor" , :overrides , "overrides/_index.scss"
74+ end
6375end
0 commit comments