|
4 | 4 | # Copyright, 2018-2025, by Samuel Williams. |
5 | 5 |
|
6 | 6 | require "fileutils" |
7 | | -require "tmpdir" |
8 | 7 | require "yaml" |
9 | 8 |
|
10 | 9 | require "bundler" |
| 10 | +require "sus/fixtures/temporary_directory_context" |
11 | 11 |
|
12 | 12 | describe "utopia command" do |
| 13 | + include Sus::Fixtures::TemporaryDirectoryContext |
| 14 | + |
13 | 15 | let(:utopia_path) {File.expand_path("../..", __dir__)} |
14 | 16 |
|
15 | 17 | def around |
@@ -40,90 +42,81 @@ def install_packages(dir) |
40 | 42 | end |
41 | 43 |
|
42 | 44 | 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 | + install_packages(root) |
| 46 | + |
| 47 | + system("bundle", "exec", "bake", "utopia:site:create", chdir: root, exception: true) |
| 48 | + |
| 49 | + expected_files = [".git", "gems.rb", "gems.locked", "readme.md", "bake.rb", "config.ru", "lib", "pages", "public", "test"] |
| 50 | + site_files = Dir.entries(root) |
| 51 | + |
| 52 | + expected_files.each do |file| |
| 53 | + expect(site_files).to be(:include?, file) |
58 | 54 | end |
| 55 | + |
| 56 | + expect( |
| 57 | + system("bundle", "exec", "bake", "test", chdir: root) |
| 58 | + ).to be == true |
59 | 59 | end |
60 | 60 |
|
61 | 61 | 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 |
| 62 | + install_packages(root) |
| 63 | + |
| 64 | + system("bundle", "exec", "bake", "utopia:server:create", chdir: root, exception: true) |
| 65 | + expect(Dir.entries(root)).to be(:include?, ".git") |
| 66 | + |
| 67 | + system("git", "config", "--local", "core.sharedRepository", "false", chdir: root, exception: true) |
| 68 | + system("chmod", "-Rf", "g-x", ".git", chdir: root, exception: true) |
| 69 | + system("rm", "-f", ".git/hooks/post-receive", chdir: root, exception: true) |
| 70 | + |
| 71 | + environment = YAML.load_file(File.join(root, "config/environment.yaml")) |
| 72 | + expect(environment).to be(:include?, "VARIANT") |
| 73 | + expect(environment).to be(:include?, "UTOPIA_SESSION_SECRET") |
76 | 74 | end |
77 | 75 |
|
78 | 76 | 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 |
| 77 | + install_packages(root) |
| 78 | + |
| 79 | + system("bundle", "exec", "bake", "utopia:server:create", chdir: root, exception: true) |
| 80 | + system("git", "config", "--local", "core.sharedRepository", "false", chdir: root, exception: true) |
| 81 | + system("chmod", "-Rf", "g-x", ".git", chdir: root, exception: true) |
| 82 | + system("rm", "-f", ".git/hooks/post-receive", chdir: root, exception: true) |
| 83 | + |
| 84 | + # Run the server update command: |
| 85 | + system("bundle", "exec", "bake", "utopia:server:update", chdir: root, exception: true) |
| 86 | + |
| 87 | + # Check a couple of files to make sure they have group read and write access after the update: |
| 88 | + Dir.glob(File.join(root, ".git/**/*")).each do |path| |
| 89 | + expect(group_rw(path)).to be == true |
94 | 90 | end |
95 | 91 | end |
96 | 92 |
|
97 | 93 | it "can generate sample site, server and push to the server" do |
98 | | - Dir.mktmpdir("test") do |dir| |
99 | | - site_path = File.join(dir, "site") |
100 | | - FileUtils.mkdir_p(site_path) |
101 | | - |
102 | | - server_path = File.join(dir, "server") |
103 | | - FileUtils.mkdir_p(server_path) |
104 | | - |
105 | | - install_packages(site_path) |
106 | | - install_packages(server_path) |
107 | | - |
108 | | - system("bundle", "exec", "bake", "utopia:site:create", chdir: site_path, exception: true) |
109 | | - branch = IO.popen(["git", "branch", "--show-current"], chdir: site_path, &:read) |
110 | | - expect(branch).to be == "main\n" |
111 | | - |
112 | | - system("bundle", "exec", "bake", "utopia:server:create", chdir: server_path, exception: true) |
113 | | - branch = IO.popen(["git", "branch", "--show-current"], chdir: server_path, &:read) |
114 | | - expect(branch).to be == "main\n" |
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) |
123 | | - 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 |
| 94 | + site_path = File.join(root, "site") |
| 95 | + FileUtils.mkdir_p(site_path) |
| 96 | + |
| 97 | + server_path = File.join(root, "server") |
| 98 | + FileUtils.mkdir_p(server_path) |
| 99 | + |
| 100 | + install_packages(site_path) |
| 101 | + install_packages(server_path) |
| 102 | + |
| 103 | + system("bundle", "exec", "bake", "utopia:site:create", chdir: site_path, exception: true) |
| 104 | + branch = IO.popen(["git", "branch", "--show-current"], chdir: site_path, &:read) |
| 105 | + expect(branch).to be == "main\n" |
| 106 | + |
| 107 | + system("bundle", "exec", "bake", "utopia:server:create", chdir: server_path, exception: true) |
| 108 | + branch = IO.popen(["git", "branch", "--show-current"], chdir: server_path, &:read) |
| 109 | + expect(branch).to be == "main\n" |
| 110 | + |
| 111 | + system("git", "push", "--set-upstream", server_path, "main", chdir: site_path, exception: true) |
| 112 | + |
| 113 | + expected_files = %W[.git gems.rb gems.locked readme.md bake.rb config.ru lib pages public] |
| 114 | + server_files = Dir.entries(server_path) |
| 115 | + |
| 116 | + expected_files.each do |file| |
| 117 | + expect(server_files).to be(:include?, file) |
127 | 118 | end |
| 119 | + |
| 120 | + expect(File.executable? File.join(server_path, "config.ru")).to be == true |
128 | 121 | end |
129 | 122 | end |
0 commit comments