|
3 | 3 |
|
4 | 4 | module Suspenders
|
5 | 5 | module Generators
|
6 |
| - class StylesGenerator::DefaultTest < Rails::Generators::TestCase |
| 6 | + class StylesGeneratorTest < Rails::Generators::TestCase |
7 | 7 | include Suspenders::TestHelpers
|
8 | 8 |
|
9 | 9 | tests Suspenders::Generators::StylesGenerator
|
@@ -45,130 +45,8 @@ class StylesGenerator::DefaultTest < Rails::Generators::TestCase
|
45 | 45 | assert_match(/bin\/rails css:install:postcss/, output)
|
46 | 46 | end
|
47 | 47 |
|
48 |
| - test "generator has a description" do |
49 |
| - description = <<~TEXT |
50 |
| - Configures applications to use PostCSS or Tailwind via cssbundling-rails. |
51 |
| - Defaults to PostCSS with modern-normalize, with the option to override via |
52 |
| - --css=tailwind. |
53 |
| -
|
54 |
| - Also creates additional stylesheets if using PostCSS. |
55 |
| - TEXT |
56 |
| - |
57 |
| - assert_equal description, generator_class.desc |
58 |
| - end |
59 |
| - |
60 |
| - private |
61 |
| - |
62 |
| - def prepare_destination |
63 |
| - touch "Gemfile" |
64 |
| - touch "app/assets/stylesheets/application.postcss.css" |
65 |
| - end |
66 |
| - |
67 |
| - def restore_destination |
68 |
| - remove_file_if_exists "Gemfile" |
69 |
| - remove_file_if_exists "package.json", root: true |
70 |
| - remove_file_if_exists "yarn.lock", root: true |
71 |
| - remove_file_if_exists "app/assets/stylesheets/application.postcss.css" |
72 |
| - remove_file_if_exists "app/assets/stylesheets/base.css" |
73 |
| - remove_file_if_exists "app/assets/stylesheets/components.css" |
74 |
| - remove_file_if_exists "app/assets/stylesheets/utilities.css" |
75 |
| - end |
76 |
| - end |
77 |
| - |
78 |
| - class StylesGenerator::ClassOptionTest < Rails::Generators::TestCase |
79 |
| - include Suspenders::TestHelpers |
80 |
| - |
81 |
| - tests Suspenders::Generators::StylesGenerator |
82 |
| - destination Rails.root |
83 |
| - setup :prepare_destination |
84 |
| - teardown :restore_destination |
85 |
| - |
86 |
| - test "has a css option" do |
87 |
| - option = generator_class.class_options[:css] |
88 |
| - |
89 |
| - assert_equal :string, option.type |
90 |
| - assert_not option.required |
91 |
| - assert_equal %w[tailwind postcss], option.enum |
92 |
| - assert_equal "postcss", option.default |
93 |
| - end |
94 |
| - |
95 |
| - test "raises if css option is unsupported" do |
96 |
| - output = capture(:stderr) { run_generator %w[--css=unknown] } |
97 |
| - |
98 |
| - assert_match(/Expected '--css' to be one of/, output) |
99 |
| - end |
100 |
| - |
101 |
| - private |
102 |
| - |
103 |
| - def prepare_destination |
104 |
| - touch "Gemfile" |
105 |
| - end |
106 |
| - |
107 |
| - def restore_destination |
108 |
| - remove_file_if_exists "Gemfile" |
109 |
| - remove_file_if_exists "package.json", root: true |
110 |
| - remove_file_if_exists "yarn.lock", root: true |
111 |
| - remove_file_if_exists "app/assets/stylesheets/application.postcss.css" |
112 |
| - remove_file_if_exists "app/assets/stylesheets/base.css" |
113 |
| - remove_file_if_exists "app/assets/stylesheets/components.css" |
114 |
| - remove_file_if_exists "app/assets/stylesheets/utilities.css" |
115 |
| - end |
116 |
| - end |
117 |
| - |
118 |
| - class StylesGenerator::TailwindTest < Rails::Generators::TestCase |
119 |
| - include Suspenders::TestHelpers |
120 |
| - |
121 |
| - tests Suspenders::Generators::StylesGenerator |
122 |
| - destination Rails.root |
123 |
| - setup :prepare_destination |
124 |
| - teardown :restore_destination |
125 |
| - |
126 |
| - test "runs install script" do |
127 |
| - output = run_generator %w[--css=tailwind] |
128 |
| - |
129 |
| - assert_match(/bin\/rails css:install:tailwind/, output) |
130 |
| - end |
131 |
| - |
132 |
| - test "does not install modern-normalize" do |
133 |
| - output = run_generator %w[--css=tailwind] |
134 |
| - |
135 |
| - assert_no_match(/add.*modern-normalize/, output) |
136 |
| - end |
137 |
| - |
138 |
| - test "does not create stylesheets" do |
139 |
| - run_generator %w[--css=tailwind] |
140 |
| - |
141 |
| - assert_no_file app_root("app/assets/stylesheets/base.css") |
142 |
| - assert_no_file app_root("app/assets/stylesheets/components.css") |
143 |
| - assert_no_file app_root("app/assets/stylesheets/utilities.css") |
144 |
| - end |
145 |
| - |
146 |
| - private |
147 |
| - |
148 |
| - def prepare_destination |
149 |
| - touch "Gemfile" |
150 |
| - end |
151 |
| - |
152 |
| - def restore_destination |
153 |
| - remove_file_if_exists "Gemfile" |
154 |
| - remove_file_if_exists "package.json", root: true |
155 |
| - remove_file_if_exists "yarn.lock", root: true |
156 |
| - remove_file_if_exists "app/assets/stylesheets/base.css" |
157 |
| - remove_file_if_exists "app/assets/stylesheets/components.css" |
158 |
| - remove_file_if_exists "app/assets/stylesheets/utilities.css" |
159 |
| - end |
160 |
| - end |
161 |
| - |
162 |
| - class StylesGenerator::PostCssTest < Rails::Generators::TestCase |
163 |
| - include Suspenders::TestHelpers |
164 |
| - |
165 |
| - tests Suspenders::Generators::StylesGenerator |
166 |
| - destination Rails.root |
167 |
| - setup :prepare_destination |
168 |
| - teardown :restore_destination |
169 |
| - |
170 | 48 | test "installs modern-normalize and imports stylesheets" do
|
171 |
| - output = run_generator %w[--css=postcss] |
| 49 | + output = run_generator |
172 | 50 | application_stylesheet = <<~TEXT
|
173 | 51 | @import "modern-normalize";
|
174 | 52 | @import "base.css";
|
@@ -197,6 +75,10 @@ class StylesGenerator::PostCssTest < Rails::Generators::TestCase
|
197 | 75 | end
|
198 | 76 | end
|
199 | 77 |
|
| 78 | + test "generator has a custom description" do |
| 79 | + assert_no_match(/Description/, generator_class.desc) |
| 80 | + end |
| 81 | + |
200 | 82 | private
|
201 | 83 |
|
202 | 84 | def prepare_destination
|
|
0 commit comments