Skip to content

Commit 8f0cd50

Browse files
committed
test: use the same temporary directory for the whole test suite
and set Rails::Generators.templates_path to include it before the generator classes are instantiated so that the local 'lib/templates' directory is part of the generators' `source_paths`. Also see railties/lib/rails/generators/base.rb and `Rails::Generators::Base.inherited`
1 parent 23869f5 commit 8f0cd50

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

Diff for: test/lib/generators/tailwindcss/controller_generator_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
class Tailwindcss::Generators::ControllerGeneratorTest < Rails::Generators::TestCase
55
tests Tailwindcss::Generators::ControllerGenerator
6-
destination Dir.mktmpdir
6+
destination TAILWINDCSS_TEST_APP_ROOT
77

88
arguments %w(Messages index show)
99

Diff for: test/lib/generators/tailwindcss/mailer_generator_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class Tailwindcss::Generators::MailerGeneratorTest < Rails::Generators::TestCase
66
tests Tailwindcss::Generators::MailerGenerator
7-
destination Dir.mktmpdir
7+
destination TAILWINDCSS_TEST_APP_ROOT
88

99
arguments %w(Notifications invoice)
1010

Diff for: test/lib/generators/tailwindcss/scaffold_generator_test.rb

+9-5
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,23 @@
33

44
class Tailwindcss::Generators::ScaffoldGeneratorTest < Rails::Generators::TestCase
55
tests Tailwindcss::Generators::ScaffoldGenerator
6-
destination Dir.mktmpdir
6+
destination TAILWINDCSS_TEST_APP_ROOT
77

88
arguments %w(message title:string content:text)
99

10-
test "generates correct view templates" do
10+
test "generates view templates" do
1111
run_generator
1212

13-
%w(index edit new show _form _message).each { |view| assert_file "app/views/messages/#{view}.html.erb" }
13+
%w(index edit new show _form _message).each do |view|
14+
assert_file "app/views/messages/#{view}.html.erb"
15+
end
1416
end
1517

16-
test "with namespace invoked" do
18+
test "generates view templates with namespace" do
1719
run_generator [ "admin/role", "name:string", "description:string" ]
1820

19-
%w(index edit new show _form _role).each { |view| assert_file "app/views/admin/roles/#{view}.html.erb" }
21+
%w(index edit new show _form _role).each do |view|
22+
assert_file "app/views/admin/roles/#{view}.html.erb"
23+
end
2024
end
2125
end

Diff for: test/test_helper.rb

+13-1
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,22 @@
44
require "rails"
55
require "rails/test_help"
66
require "debug"
7-
require_relative "../lib/tailwindcss-rails"
87

98
require "rails/test_unit/reporter"
109
Rails::TestUnitReporter.executable = "bin/test"
1110

11+
TAILWINDCSS_TEST_APP_ROOT = Dir.mktmpdir
12+
Rails::Generators.templates_path << File.join(TAILWINDCSS_TEST_APP_ROOT, "lib/templates")
13+
1214
class ActiveSupport::TestCase
15+
def setup
16+
FileUtils.rm_rf(TAILWINDCSS_TEST_APP_ROOT)
17+
FileUtils.mkdir_p(TAILWINDCSS_TEST_APP_ROOT)
18+
end
19+
20+
def teardown
21+
FileUtils.rm_rf(TAILWINDCSS_TEST_APP_ROOT)
22+
end
1323
end
24+
25+
require_relative "../lib/tailwindcss-rails"

0 commit comments

Comments
 (0)