Skip to content

Commit dd1c240

Browse files
Use Sus temporary directory fixture
Assisted-By: devx/648e2c48-7c87-49c5-b3db-7a3e62d0fbbc
1 parent 823ba79 commit dd1c240

1 file changed

Lines changed: 71 additions & 69 deletions

File tree

test/utopia/command.rb

Lines changed: 71 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
# Copyright, 2018-2025, by Samuel Williams.
55

66
require "fileutils"
7-
require "tmpdir"
87
require "yaml"
98

109
require "bundler"
10+
require "sus/fixtures/temporary_directory_context"
1111

1212
describe "utopia command" do
13+
include Sus::Fixtures::TemporaryDirectoryContext
14+
1315
let(:utopia_path) {File.expand_path("../..", __dir__)}
1416

1517
def around
@@ -40,87 +42,87 @@ def install_packages(dir)
4042
end
4143

4244
it "should generate sample site" do
43-
Dir.mktmpdir("test-site") do |dir|
44-
install_packages(dir)
45-
46-
system("bundle", "exec", "bake", "utopia:site:create", chdir: dir, exception: true)
47-
48-
expected_files = [".git", "gems.rb", "gems.locked", "readme.md", "bake.rb", "config.ru", "lib", "pages", "public", "test"]
49-
site_files = Dir.entries(dir)
50-
51-
expected_files.each do |file|
52-
expect(site_files).to be(:include?, file)
53-
end
54-
55-
expect(
56-
system("bundle", "exec", "bake", "test", chdir: dir)
57-
).to be == true
45+
dir = root
46+
47+
install_packages(dir)
48+
49+
system("bundle", "exec", "bake", "utopia:site:create", chdir: dir, exception: true)
50+
51+
expected_files = [".git", "gems.rb", "gems.locked", "readme.md", "bake.rb", "config.ru", "lib", "pages", "public", "test"]
52+
site_files = Dir.entries(dir)
53+
54+
expected_files.each do |file|
55+
expect(site_files).to be(:include?, file)
5856
end
57+
58+
expect(
59+
system("bundle", "exec", "bake", "test", chdir: dir)
60+
).to be == true
5961
end
6062

6163
it "should generate a sample server" do
62-
Dir.mktmpdir("test-server") do |dir|
63-
install_packages(dir)
64-
65-
system("bundle", "exec", "bake", "utopia:server:create", chdir: dir, exception: true)
66-
expect(Dir.entries(dir)).to be(:include?, ".git")
67-
68-
system("git", "config", "--local", "core.sharedRepository", "false", chdir: dir, exception: true)
69-
system("chmod", "-Rf", "g-x", ".git", chdir: dir, exception: true)
70-
system("rm", "-f", ".git/hooks/post-receive", chdir: dir, exception: true)
71-
72-
environment = YAML.load_file(File.join(dir, "config/environment.yaml"))
73-
expect(environment).to be(:include?, "VARIANT")
74-
expect(environment).to be(:include?, "UTOPIA_SESSION_SECRET")
75-
end
64+
dir = root
65+
66+
install_packages(dir)
67+
68+
system("bundle", "exec", "bake", "utopia:server:create", chdir: dir, exception: true)
69+
expect(Dir.entries(dir)).to be(:include?, ".git")
70+
71+
system("git", "config", "--local", "core.sharedRepository", "false", chdir: dir, exception: true)
72+
system("chmod", "-Rf", "g-x", ".git", chdir: dir, exception: true)
73+
system("rm", "-f", ".git/hooks/post-receive", chdir: dir, exception: true)
74+
75+
environment = YAML.load_file(File.join(dir, "config/environment.yaml"))
76+
expect(environment).to be(:include?, "VARIANT")
77+
expect(environment).to be(:include?, "UTOPIA_SESSION_SECRET")
7678
end
7779

7880
it "should not trash the sample server during update" do
79-
Dir.mktmpdir("test-server") do |dir|
80-
install_packages(dir)
81-
82-
system("bundle", "exec", "bake", "utopia:server:create", chdir: dir, exception: true)
83-
system("git", "config", "--local", "core.sharedRepository", "false", chdir: dir, exception: true)
84-
system("chmod", "-Rf", "g-x", ".git", chdir: dir, exception: true)
85-
system("rm", "-f", ".git/hooks/post-receive", chdir: dir, exception: true)
86-
87-
# Run the server update command:
88-
system("bundle", "exec", "bake", "utopia:server:update", chdir: dir, exception: true)
89-
90-
# Check a couple of files to make sure they have group read and write access after the update:
91-
Dir.glob(File.join(dir, ".git/**/*")).each do |path|
92-
expect(group_rw(path)).to be == true
93-
end
81+
dir = root
82+
83+
install_packages(dir)
84+
85+
system("bundle", "exec", "bake", "utopia:server:create", chdir: dir, exception: true)
86+
system("git", "config", "--local", "core.sharedRepository", "false", chdir: dir, exception: true)
87+
system("chmod", "-Rf", "g-x", ".git", chdir: dir, exception: true)
88+
system("rm", "-f", ".git/hooks/post-receive", chdir: dir, exception: true)
89+
90+
# Run the server update command:
91+
system("bundle", "exec", "bake", "utopia:server:update", chdir: dir, exception: true)
92+
93+
# Check a couple of files to make sure they have group read and write access after the update:
94+
Dir.glob(File.join(dir, ".git/**/*")).each do |path|
95+
expect(group_rw(path)).to be == true
9496
end
9597
end
9698

9799
it "can generate sample site, server and push to the server" do
98100
# This assumes your default branch is "main". We should probably be more flexible around this.
99101
# git config --global init.defaultBranch main
100-
Dir.mktmpdir("test") do |dir|
101-
site_path = File.join(dir, "site")
102-
FileUtils.mkdir_p(site_path)
103-
104-
server_path = File.join(dir, "server")
105-
FileUtils.mkdir_p(server_path)
106-
107-
install_packages(site_path)
108-
install_packages(server_path)
109-
110-
system("bundle", "exec", "bake", "utopia:site:create", chdir: site_path, exception: true)
111-
system("bundle", "exec", "bake", "utopia:server:create", chdir: server_path, exception: true)
112-
113-
system("git", "push", "--set-upstream", server_path, "main", chdir: site_path, exception: true)
114-
115-
expected_files = %W[.git gems.rb gems.locked readme.md bake.rb config.ru lib pages public]
116-
server_files = Dir.entries(server_path)
117-
118-
expected_files.each do |file|
119-
expect(server_files).to be(:include?, file)
120-
end
121-
122-
expect(File.executable? File.join(server_path, "config.ru")).to be == true
123-
puts File.stat(File.join(dir, "server", ".git")).mode
102+
dir = root
103+
104+
site_path = File.join(dir, "site")
105+
FileUtils.mkdir_p(site_path)
106+
107+
server_path = File.join(dir, "server")
108+
FileUtils.mkdir_p(server_path)
109+
110+
install_packages(site_path)
111+
install_packages(server_path)
112+
113+
system("bundle", "exec", "bake", "utopia:site:create", chdir: site_path, exception: true)
114+
system("bundle", "exec", "bake", "utopia:server:create", chdir: server_path, exception: true)
115+
116+
system("git", "push", "--set-upstream", server_path, "main", chdir: site_path, exception: true)
117+
118+
expected_files = %W[.git gems.rb gems.locked readme.md bake.rb config.ru lib pages public]
119+
server_files = Dir.entries(server_path)
120+
121+
expected_files.each do |file|
122+
expect(server_files).to be(:include?, file)
124123
end
124+
125+
expect(File.executable? File.join(server_path, "config.ru")).to be == true
126+
puts File.stat(File.join(dir, "server", ".git")).mode
125127
end
126128
end

0 commit comments

Comments
 (0)