geb 0.1.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +3 -0
- data/CHANGELOG.md +37 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/LICENSE +21 -0
- data/README.md +384 -0
- data/Rakefile +21 -0
- data/bin/geb +21 -0
- data/lib/geb/cli.rb +40 -0
- data/lib/geb/commands/build.rb +59 -0
- data/lib/geb/commands/init.rb +70 -0
- data/lib/geb/commands/release.rb +54 -0
- data/lib/geb/commands/remote.rb +48 -0
- data/lib/geb/commands/server.rb +77 -0
- data/lib/geb/commands/upload.rb +48 -0
- data/lib/geb/commands/version.rb +36 -0
- data/lib/geb/config.rb +103 -0
- data/lib/geb/defaults.rb +44 -0
- data/lib/geb/git.rb +112 -0
- data/lib/geb/page.rb +217 -0
- data/lib/geb/partial.rb +150 -0
- data/lib/geb/samples/basic/assets/css/site.css +7 -0
- data/lib/geb/samples/basic/assets/images/android-chrome-192x192.png +0 -0
- data/lib/geb/samples/basic/assets/images/android-chrome-512x512.png +0 -0
- data/lib/geb/samples/basic/assets/images/apple-touch-icon.png +0 -0
- data/lib/geb/samples/basic/assets/images/favicon-16x16.png +0 -0
- data/lib/geb/samples/basic/assets/images/favicon-32x32.png +0 -0
- data/lib/geb/samples/basic/assets/images/favicon.ico +0 -0
- data/lib/geb/samples/basic/assets/images/hero.png +0 -0
- data/lib/geb/samples/basic/assets/images/og-thumb.png +0 -0
- data/lib/geb/samples/basic/assets/images/twitter-thumb.png +0 -0
- data/lib/geb/samples/basic/assets/js/site.js +5 -0
- data/lib/geb/samples/basic/geb.config.yml +70 -0
- data/lib/geb/samples/basic/index.html +11 -0
- data/lib/geb/samples/basic/page.html +11 -0
- data/lib/geb/samples/basic/shared/partials/_analytics.html +9 -0
- data/lib/geb/samples/basic/shared/partials/_footer.html +3 -0
- data/lib/geb/samples/basic/shared/partials/_global_assets.html +19 -0
- data/lib/geb/samples/basic/shared/partials/_header.html +0 -0
- data/lib/geb/samples/basic/shared/partials/_meta_tags.html +34 -0
- data/lib/geb/samples/basic/shared/templates/_blog_post.html +0 -0
- data/lib/geb/samples/basic/shared/templates/_site.html +19 -0
- data/lib/geb/samples/basic/site.webmanifest +1 -0
- data/lib/geb/samples/bootstrap_jquery/assets/css/site.css +7 -0
- data/lib/geb/samples/bootstrap_jquery/assets/images/android-chrome-192x192.png +0 -0
- data/lib/geb/samples/bootstrap_jquery/assets/images/android-chrome-512x512.png +0 -0
- data/lib/geb/samples/bootstrap_jquery/assets/images/apple-touch-icon.png +0 -0
- data/lib/geb/samples/bootstrap_jquery/assets/images/favicon-16x16.png +0 -0
- data/lib/geb/samples/bootstrap_jquery/assets/images/favicon-32x32.png +0 -0
- data/lib/geb/samples/bootstrap_jquery/assets/images/favicon.ico +0 -0
- data/lib/geb/samples/bootstrap_jquery/assets/images/hero.png +0 -0
- data/lib/geb/samples/bootstrap_jquery/assets/images/og-thumb.png +0 -0
- data/lib/geb/samples/bootstrap_jquery/assets/images/twitter-thumb.png +0 -0
- data/lib/geb/samples/bootstrap_jquery/assets/js/site.js +5 -0
- data/lib/geb/samples/bootstrap_jquery/blog/blog_post_1.html +35 -0
- data/lib/geb/samples/bootstrap_jquery/blog/blog_post_2.html +35 -0
- data/lib/geb/samples/bootstrap_jquery/blog/blog_post_3.html +35 -0
- data/lib/geb/samples/bootstrap_jquery/blog/index.html +17 -0
- data/lib/geb/samples/bootstrap_jquery/geb.config.yml +69 -0
- data/lib/geb/samples/bootstrap_jquery/index.html +11 -0
- data/lib/geb/samples/bootstrap_jquery/page.html +11 -0
- data/lib/geb/samples/bootstrap_jquery/shared/partials/_analytics.html +9 -0
- data/lib/geb/samples/bootstrap_jquery/shared/partials/_footer.html +3 -0
- data/lib/geb/samples/bootstrap_jquery/shared/partials/_global_assets.html +19 -0
- data/lib/geb/samples/bootstrap_jquery/shared/partials/_header.html +0 -0
- data/lib/geb/samples/bootstrap_jquery/shared/partials/_meta_tags.html +34 -0
- data/lib/geb/samples/bootstrap_jquery/shared/templates/_blog_post.html +0 -0
- data/lib/geb/samples/bootstrap_jquery/shared/templates/_site.html +19 -0
- data/lib/geb/samples/bootstrap_jquery/site.webmanifest +1 -0
- data/lib/geb/samples/geb.config.yml +70 -0
- data/lib/geb/server.rb +138 -0
- data/lib/geb/site/build.rb +189 -0
- data/lib/geb/site/core.rb +229 -0
- data/lib/geb/site/release.rb +70 -0
- data/lib/geb/site/remote.rb +142 -0
- data/lib/geb/site/template.rb +208 -0
- data/lib/geb/site.rb +83 -0
- data/lib/geb/template.rb +166 -0
- data/lib/geb/utilities.rb +110 -0
- data/lib/geb.rb +36 -0
- data/lib/seth.rb +50 -0
- data/sig/geb.rbs +4 -0
- data/test/api tests/test_cli.rb +200 -0
- data/test/api tests/test_config.rb +330 -0
- data/test/api tests/test_defaults.rb +62 -0
- data/test/api tests/test_git.rb +105 -0
- data/test/api tests/test_page.rb +320 -0
- data/test/api tests/test_partial.rb +152 -0
- data/test/api tests/test_server.rb +416 -0
- data/test/api tests/test_site.rb +1315 -0
- data/test/api tests/test_template.rb +249 -0
- data/test/api tests/test_utilities.rb +162 -0
- data/test/command tests/test_geb_build.rb +199 -0
- data/test/command tests/test_geb_init.rb +312 -0
- data/test/command tests/test_geb_release.rb +166 -0
- data/test/command tests/test_geb_remote.rb +66 -0
- data/test/command tests/test_geb_server.rb +122 -0
- data/test/command tests/test_geb_upload.rb +96 -0
- data/test/command tests/test_geb_version.rb +58 -0
- data/test/support/geb_api_test.rb +37 -0
- data/test/support/geb_cli_test.rb +275 -0
- data/test/support/geb_minitest_ext.rb +35 -0
- data/test/support/geb_test_helpers.rb +84 -0
- data/test/support/geb_web_server_proxy.rb +128 -0
- data/test/test_helper.rb +61 -0
- metadata +301 -0
@@ -0,0 +1,200 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# Tests the CLI commands for Geb commands, making sure that DRY::CLI
|
4
|
+
# structure is correctly implemented
|
5
|
+
#
|
6
|
+
# @title Geb - Test - CLI
|
7
|
+
# @author Edin Mustajbegovic <edin@actiontwelve.com>
|
8
|
+
# @copyright 2024 Edin Mustajbegovic
|
9
|
+
# @license MIT
|
10
|
+
#
|
11
|
+
# @see https://github.com/mainfram-work/geb for more information
|
12
|
+
|
13
|
+
require "test_helper"
|
14
|
+
|
15
|
+
class TestCli < Minitest::Test
|
16
|
+
|
17
|
+
test "that geb has a version number" do
|
18
|
+
refute_nil Geb::VERSION
|
19
|
+
end # test "that geb has a version number"
|
20
|
+
|
21
|
+
test "that all geb commands are registered" do
|
22
|
+
|
23
|
+
refute_nil Geb::CLI::Commands::Release
|
24
|
+
refute_nil Geb::CLI::Commands::Build
|
25
|
+
refute_nil Geb::CLI::Commands::Server
|
26
|
+
refute_nil Geb::CLI::Commands::Init
|
27
|
+
refute_nil Geb::CLI::Commands::Upload
|
28
|
+
refute_nil Geb::CLI::Commands::Remote
|
29
|
+
refute_nil Geb::CLI::Commands::Version
|
30
|
+
|
31
|
+
cli = Dry::CLI.new(Geb::CLI::Commands)
|
32
|
+
registry = cli.instance_variable_get(:@registry)
|
33
|
+
|
34
|
+
assert_cli_registered_command registry, "release", Geb::CLI::Commands::Release
|
35
|
+
assert_cli_registered_command registry, "build", Geb::CLI::Commands::Build
|
36
|
+
assert_cli_registered_command registry, "server", Geb::CLI::Commands::Server
|
37
|
+
assert_cli_registered_command registry, "init", Geb::CLI::Commands::Init
|
38
|
+
assert_cli_registered_command registry, "upload", Geb::CLI::Commands::Upload
|
39
|
+
assert_cli_registered_command registry, "remote", Geb::CLI::Commands::Remote
|
40
|
+
assert_cli_registered_command registry, "version", Geb::CLI::Commands::Version
|
41
|
+
|
42
|
+
end # test "that all geb commands are registered"
|
43
|
+
|
44
|
+
test "that all geb commands show help correctly" do
|
45
|
+
|
46
|
+
# build a hash of all commands (key is command name, value is commmand class instance)
|
47
|
+
commands = {}
|
48
|
+
commands["release"] = Geb::CLI::Commands::Release.new
|
49
|
+
commands["build"] = Geb::CLI::Commands::Build.new
|
50
|
+
commands["server"] = Geb::CLI::Commands::Server.new
|
51
|
+
commands["init"] = Geb::CLI::Commands::Init.new
|
52
|
+
commands["upload"] = Geb::CLI::Commands::Upload.new
|
53
|
+
commands["remote"] = Geb::CLI::Commands::Remote.new
|
54
|
+
commands["version"] = Geb::CLI::Commands::Version.new
|
55
|
+
|
56
|
+
# check the version first
|
57
|
+
stdout, stderr, status = Open3.capture3("geb version")
|
58
|
+
|
59
|
+
assert status.success?
|
60
|
+
assert_empty stderr
|
61
|
+
assert_includes stdout, "Geb version #{Geb::VERSION}"
|
62
|
+
|
63
|
+
# iterate over all commands
|
64
|
+
commands.each do |name, command|
|
65
|
+
|
66
|
+
# call geb auto command and capture output and error
|
67
|
+
stdout, stderr, status = Open3.capture3("geb #{name} --help")
|
68
|
+
|
69
|
+
# assert that the output contains the expected string
|
70
|
+
assert status.success?
|
71
|
+
assert_empty stderr
|
72
|
+
assert_includes stdout, "geb #{name}"
|
73
|
+
assert_includes stdout, command.description
|
74
|
+
command.options.each do |option|
|
75
|
+
assert_includes stdout, option.name.to_s
|
76
|
+
assert_includes stdout, option.desc
|
77
|
+
end
|
78
|
+
|
79
|
+
end # each
|
80
|
+
|
81
|
+
end # test "that all geb commands show help correctly"
|
82
|
+
|
83
|
+
test "that geb has a build command" do
|
84
|
+
|
85
|
+
refute_nil Geb::CLI::Commands::Build
|
86
|
+
refute_nil Geb::CLI::Commands::Build.method_defined?(:call)
|
87
|
+
assert_equal Dry::CLI::Command, Geb::CLI::Commands::Build.superclass
|
88
|
+
|
89
|
+
refute_nil Geb::CLI::Commands::Build.description, "Build command should have a description."
|
90
|
+
refute_empty Geb::CLI::Commands::Build.description, "Build command's description should not be empty."
|
91
|
+
refute_nil Geb::CLI::Commands::Build.example, "Build command should have an example."
|
92
|
+
refute_empty Geb::CLI::Commands::Build.example, "Build command's example should not be empty."
|
93
|
+
|
94
|
+
refute_nil Geb::CLI::Commands::Build.method_defined?(:options)
|
95
|
+
refute_empty Geb::CLI::Commands::Build.options, "Build command should have options."
|
96
|
+
|
97
|
+
assert_cli_option Geb::CLI::Commands::Build, :skip_assets, :boolean, false
|
98
|
+
assert_cli_option Geb::CLI::Commands::Build, :skip_pages, :boolean, false
|
99
|
+
|
100
|
+
end # test "that geb has a build command"
|
101
|
+
|
102
|
+
test "that geb has a release command" do
|
103
|
+
|
104
|
+
refute_nil Geb::CLI::Commands::Release
|
105
|
+
refute_nil Geb::CLI::Commands::Release.method_defined?(:call)
|
106
|
+
assert_equal Dry::CLI::Command, Geb::CLI::Commands::Release.superclass
|
107
|
+
|
108
|
+
refute_nil Geb::CLI::Commands::Release.description, "Release command should have a description."
|
109
|
+
refute_empty Geb::CLI::Commands::Release.description, "Release command's description should not be empty."
|
110
|
+
refute_nil Geb::CLI::Commands::Release.example, "Release command should have an example."
|
111
|
+
refute_empty Geb::CLI::Commands::Release.example, "Release command's example should not be empty."
|
112
|
+
|
113
|
+
refute_nil Geb::CLI::Commands::Release.method_defined?(:options)
|
114
|
+
refute_empty Geb::CLI::Commands::Release.options, "Release command should have options."
|
115
|
+
|
116
|
+
assert_cli_option Geb::CLI::Commands::Release, :with_template, :boolean, false
|
117
|
+
|
118
|
+
end # test "that geb has a release command"
|
119
|
+
|
120
|
+
test "that geb has a server command" do
|
121
|
+
|
122
|
+
refute_nil Geb::CLI::Commands::Server
|
123
|
+
refute_nil Geb::CLI::Commands::Server.method_defined?(:call)
|
124
|
+
assert_equal Dry::CLI::Command, Geb::CLI::Commands::Server.superclass
|
125
|
+
|
126
|
+
refute_nil Geb::CLI::Commands::Server.description, "Server command should have a description."
|
127
|
+
refute_empty Geb::CLI::Commands::Server.description, "Server command's description should not be empty."
|
128
|
+
refute_nil Geb::CLI::Commands::Server.example, "Server command should have an example."
|
129
|
+
refute_empty Geb::CLI::Commands::Server.example, "Server command's example should not be empty."
|
130
|
+
|
131
|
+
refute_nil Geb::CLI::Commands::Server.method_defined?(:options)
|
132
|
+
refute_empty Geb::CLI::Commands::Server.options, "Server command should have options."
|
133
|
+
|
134
|
+
assert_cli_option Geb::CLI::Commands::Server, :port, :int, 0
|
135
|
+
assert_cli_option Geb::CLI::Commands::Server, :skip_build, :boolean, false
|
136
|
+
|
137
|
+
end # test "that geb has a server command"
|
138
|
+
|
139
|
+
test "that geb has a init command" do
|
140
|
+
|
141
|
+
refute_nil Geb::CLI::Commands::Init
|
142
|
+
refute_nil Geb::CLI::Commands::Init.method_defined?(:call)
|
143
|
+
assert_equal Dry::CLI::Command, Geb::CLI::Commands::Init.superclass
|
144
|
+
|
145
|
+
refute_nil Geb::CLI::Commands::Init.description, "Init command should have a description."
|
146
|
+
refute_empty Geb::CLI::Commands::Init.description, "Init command's description should not be empty."
|
147
|
+
refute_nil Geb::CLI::Commands::Init.example, "Init command should have an example."
|
148
|
+
refute_empty Geb::CLI::Commands::Init.example, "Init command's example should not be empty."
|
149
|
+
|
150
|
+
refute_nil Geb::CLI::Commands::Init.method_defined?(:options)
|
151
|
+
refute_empty Geb::CLI::Commands::Init.options, "Init command should have options."
|
152
|
+
|
153
|
+
assert_cli_option Geb::CLI::Commands::Init, :template, :string, nil
|
154
|
+
assert_cli_option Geb::CLI::Commands::Init, :skip_template, :boolean, false
|
155
|
+
assert_cli_option Geb::CLI::Commands::Init, :skip_git, :boolean, false
|
156
|
+
assert_cli_option Geb::CLI::Commands::Init, :force, :boolean, false
|
157
|
+
|
158
|
+
end # test "that geb has a init command"
|
159
|
+
|
160
|
+
test "that geb has a upload command" do
|
161
|
+
|
162
|
+
refute_nil Geb::CLI::Commands::Upload
|
163
|
+
refute_nil Geb::CLI::Commands::Upload.method_defined?(:call)
|
164
|
+
assert_equal Dry::CLI::Command, Geb::CLI::Commands::Upload.superclass
|
165
|
+
|
166
|
+
refute_nil Geb::CLI::Commands::Upload.description, "Upload command should have a description."
|
167
|
+
refute_empty Geb::CLI::Commands::Upload.description, "Upload command's description should not be empty."
|
168
|
+
refute_nil Geb::CLI::Commands::Upload.example, "Upload command should have an example."
|
169
|
+
refute_empty Geb::CLI::Commands::Upload.example, "Upload command's example should not be empty."
|
170
|
+
|
171
|
+
|
172
|
+
end # test "that geb has a upload command"
|
173
|
+
|
174
|
+
test "that geb has a remote command" do
|
175
|
+
|
176
|
+
refute_nil Geb::CLI::Commands::Remote
|
177
|
+
refute_nil Geb::CLI::Commands::Remote.method_defined?(:call)
|
178
|
+
assert_equal Dry::CLI::Command, Geb::CLI::Commands::Remote.superclass
|
179
|
+
|
180
|
+
refute_nil Geb::CLI::Commands::Remote.description, "Remote command should have a description."
|
181
|
+
refute_empty Geb::CLI::Commands::Remote.description, "Remote command's description should not be empty."
|
182
|
+
refute_nil Geb::CLI::Commands::Remote.example, "Remote command should have an example."
|
183
|
+
refute_empty Geb::CLI::Commands::Remote.example, "Remote command's example should not be empty."
|
184
|
+
|
185
|
+
end # test "that geb has a remote command"
|
186
|
+
|
187
|
+
test "that geb has a version command" do
|
188
|
+
|
189
|
+
refute_nil Geb::CLI::Commands::Version
|
190
|
+
refute_nil Geb::CLI::Commands::Version.method_defined?(:call)
|
191
|
+
assert_equal Dry::CLI::Command, Geb::CLI::Commands::Version.superclass
|
192
|
+
|
193
|
+
refute_nil Geb::CLI::Commands::Version.description, "Version command should have a description."
|
194
|
+
refute_empty Geb::CLI::Commands::Version.description, "Version command's description should not be empty."
|
195
|
+
refute_nil Geb::CLI::Commands::Version.example, "Version command should have an example."
|
196
|
+
refute_empty Geb::CLI::Commands::Version.example, "Version command's example should not be empty."
|
197
|
+
|
198
|
+
end # test "that geb has a version command"
|
199
|
+
|
200
|
+
end # class TestCli < Minitest::Test
|
@@ -0,0 +1,330 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# Tests the site config class for the Geb gem.
|
4
|
+
#
|
5
|
+
# @title Geb - Test - Config
|
6
|
+
# @author Edin Mustajbegovic <edin@actiontwelve.com>
|
7
|
+
# @copyright 2024 Edin Mustajbegovic
|
8
|
+
# @license MIT
|
9
|
+
#
|
10
|
+
# @see https://github.com/mainfram-work/geb for more information
|
11
|
+
|
12
|
+
require "test_helper"
|
13
|
+
|
14
|
+
class TestConfig < Minitest::Test
|
15
|
+
|
16
|
+
test "that the site directory find test site config file" do
|
17
|
+
|
18
|
+
site_path = File.join(File.dirname(__FILE__), "..", "files", "test-site")
|
19
|
+
|
20
|
+
assert Geb::Config.site_directory_has_config?(site_path)
|
21
|
+
|
22
|
+
end # test "that the site directory has a config file uses the correct defaults"
|
23
|
+
|
24
|
+
test "that the site directory find test site config file uses correct defaults" do
|
25
|
+
|
26
|
+
site_path = File.join(File.dirname(__FILE__), "..", "files", "test-site")
|
27
|
+
File.expects(:join).with(site_path, Geb::Defaults::SITE_CONFIG_FILENAME)
|
28
|
+
File.expects(:exist?).returns(true)
|
29
|
+
|
30
|
+
Geb::Config.site_directory_has_config?(site_path)
|
31
|
+
|
32
|
+
end # test "that the site directory has a config file uses the correct defaults"
|
33
|
+
|
34
|
+
test "that configuration object is initialized correctly" do
|
35
|
+
|
36
|
+
site = Geb::Site.new
|
37
|
+
site_path = File.join(File.dirname(__FILE__), "..", "files", "test-site")
|
38
|
+
|
39
|
+
site.instance_variable_set :@site_path, site_path
|
40
|
+
Geb::Config.expects(:site_directory_has_config?).returns(true)
|
41
|
+
YAML.expects(:load_file).with(File.join(site_path, Geb::Defaults::SITE_CONFIG_FILENAME)).returns({})
|
42
|
+
|
43
|
+
config = Geb::Config.new(site)
|
44
|
+
|
45
|
+
refute_nil config
|
46
|
+
assert_instance_of Geb::Config, config
|
47
|
+
|
48
|
+
end # test "that configuration object is initialized correctly"
|
49
|
+
|
50
|
+
test "that the configuration object raises an error if the site directory has no config file" do
|
51
|
+
|
52
|
+
site = Geb::Site.new
|
53
|
+
site_path = "fake_file_path"
|
54
|
+
|
55
|
+
site.instance_variable_set :@site_path, site_path
|
56
|
+
Geb::Config.expects(:site_directory_has_config?).returns(false)
|
57
|
+
|
58
|
+
error = assert_raises(Geb::Config::ConfigFileNotFound) do
|
59
|
+
Geb::Config.new(site)
|
60
|
+
end
|
61
|
+
|
62
|
+
assert_includes error.message, "Site path [#{site_path}] has no geb configuration."
|
63
|
+
|
64
|
+
end # test "that the configuration object raises an error if the site directory has no config file"
|
65
|
+
|
66
|
+
test "that the site name is returned as folder name if no site name config" do
|
67
|
+
|
68
|
+
site = Geb::Site.new
|
69
|
+
site_name = "test-site22"
|
70
|
+
site_path = File.join(File.dirname(__FILE__), "..", "files", site_name)
|
71
|
+
|
72
|
+
site.instance_variable_set :@site_path, site_path
|
73
|
+
Geb::Config.expects(:site_directory_has_config?).returns(true)
|
74
|
+
YAML.expects(:load_file).returns(nil)
|
75
|
+
|
76
|
+
config = Geb::Config.new(site)
|
77
|
+
|
78
|
+
assert_equal site_name, config.site_name
|
79
|
+
|
80
|
+
end # test "that the site name is returned as folder name if no site name config"
|
81
|
+
|
82
|
+
test "that the site name is returned as config value if set" do
|
83
|
+
|
84
|
+
site = Geb::Site.new
|
85
|
+
site_name = "test-site22"
|
86
|
+
site_path = File.join(File.dirname(__FILE__), "..", "files", "fake_site")
|
87
|
+
|
88
|
+
site.instance_variable_set :@site_path, site_path
|
89
|
+
Geb::Config.expects(:site_directory_has_config?).returns(true)
|
90
|
+
YAML.stubs(:load_file).returns({'site_name' => site_name})
|
91
|
+
|
92
|
+
config = Geb::Config.new(site)
|
93
|
+
|
94
|
+
assert_equal site_name, config.site_name
|
95
|
+
|
96
|
+
end # test "that the site name is returned as config value if set"
|
97
|
+
|
98
|
+
test "that the remote uri is returned as nil if not set" do
|
99
|
+
|
100
|
+
site = Geb::Site.new
|
101
|
+
site_path = File.join(File.dirname(__FILE__), "..", "files", "fake_site")
|
102
|
+
|
103
|
+
site.instance_variable_set :@site_path, site_path
|
104
|
+
Geb::Config.expects(:site_directory_has_config?).returns(true)
|
105
|
+
YAML.stubs(:load_file).returns({})
|
106
|
+
|
107
|
+
config = Geb::Config.new(site)
|
108
|
+
|
109
|
+
assert_nil config.remote_uri
|
110
|
+
|
111
|
+
end # test "that the remote uri is returned as nil if not set"
|
112
|
+
|
113
|
+
test "that the remote uri is returned as config value if set" do
|
114
|
+
|
115
|
+
site = Geb::Site.new
|
116
|
+
remote_uri = "https://example.com"
|
117
|
+
site_path = File.join(File.dirname(__FILE__), "..", "files", "fake_site")
|
118
|
+
|
119
|
+
site.instance_variable_set :@site_path, site_path
|
120
|
+
Geb::Config.expects(:site_directory_has_config?).returns(true)
|
121
|
+
YAML.stubs(:load_file).returns({'remote_uri' => remote_uri})
|
122
|
+
|
123
|
+
config = Geb::Config.new(site)
|
124
|
+
|
125
|
+
assert_equal remote_uri, config.remote_uri
|
126
|
+
|
127
|
+
end # test "that the remote uri is returned as config value if set"
|
128
|
+
|
129
|
+
test "that the remote path is returned as nil if not set" do
|
130
|
+
|
131
|
+
site = Geb::Site.new
|
132
|
+
site_path = File.join(File.dirname(__FILE__), "..", "files", "fake_site")
|
133
|
+
|
134
|
+
site.instance_variable_set :@site_path, site_path
|
135
|
+
Geb::Config.expects(:site_directory_has_config?).returns(true)
|
136
|
+
YAML.stubs(:load_file).returns({})
|
137
|
+
|
138
|
+
config = Geb::Config.new(site)
|
139
|
+
|
140
|
+
assert_nil config.remote_path
|
141
|
+
|
142
|
+
end # test "that the remote path is returned as nil if not set"
|
143
|
+
|
144
|
+
test "that the remote path is returned as config value if set" do
|
145
|
+
|
146
|
+
site = Geb::Site.new
|
147
|
+
remote_path = "/var/www/html"
|
148
|
+
site_path = File.join(File.dirname(__FILE__), "..", "files", "fake_site")
|
149
|
+
|
150
|
+
site.instance_variable_set :@site_path, site_path
|
151
|
+
Geb::Config.expects(:site_directory_has_config?).returns(true)
|
152
|
+
YAML.stubs(:load_file).returns({'remote_path' => remote_path})
|
153
|
+
|
154
|
+
config = Geb::Config.new(site)
|
155
|
+
|
156
|
+
assert_equal remote_path, config.remote_path
|
157
|
+
|
158
|
+
end # test "that the remote path is returned
|
159
|
+
|
160
|
+
test "that the local port is returned as nil if not set" do
|
161
|
+
|
162
|
+
site = Geb::Site.new
|
163
|
+
site_path = File.join(File.dirname(__FILE__), "..", "files", "fake_site")
|
164
|
+
|
165
|
+
site.instance_variable_set :@site_path, site_path
|
166
|
+
Geb::Config.expects(:site_directory_has_config?).returns(true)
|
167
|
+
YAML.stubs(:load_file).returns({})
|
168
|
+
|
169
|
+
config = Geb::Config.new(site)
|
170
|
+
|
171
|
+
assert_nil config.local_port
|
172
|
+
|
173
|
+
end # test "that the local port is returned as nil if not set"
|
174
|
+
|
175
|
+
test "that the local port is returned as config value if set" do
|
176
|
+
|
177
|
+
site = Geb::Site.new
|
178
|
+
local_port = 8080
|
179
|
+
site_path = File.join(File.dirname(__FILE__), "..", "files", "fake_site")
|
180
|
+
|
181
|
+
site.instance_variable_set :@site_path, site_path
|
182
|
+
Geb::Config.expects(:site_directory_has_config?).returns(true)
|
183
|
+
YAML.stubs(:load_file).returns({'local_port' => local_port})
|
184
|
+
|
185
|
+
config = Geb::Config.new(site)
|
186
|
+
|
187
|
+
assert_equal local_port, config.local_port
|
188
|
+
|
189
|
+
end # test "that the local port is returned as config value if set"
|
190
|
+
|
191
|
+
test "that the output directory is returned as default if not set" do
|
192
|
+
|
193
|
+
site = Geb::Site.new
|
194
|
+
site_path = File.join(File.dirname(__FILE__), "..", "files", "fake_site")
|
195
|
+
|
196
|
+
site.instance_variable_set :@site_path, site_path
|
197
|
+
Geb::Config.expects(:site_directory_has_config?).returns(true)
|
198
|
+
YAML.stubs(:load_file).returns({})
|
199
|
+
|
200
|
+
config = Geb::Config.new(site)
|
201
|
+
|
202
|
+
assert_equal Geb::Defaults::OUTPUT_DIR, config.output_dir
|
203
|
+
|
204
|
+
end # test "that the output directory is returned as default if not set"
|
205
|
+
|
206
|
+
test "that the output directory is returned as config value if set" do
|
207
|
+
|
208
|
+
site = Geb::Site.new
|
209
|
+
output_dir = "public"
|
210
|
+
site_path = File.join(File.dirname(__FILE__), "..", "files", "fake_site")
|
211
|
+
|
212
|
+
site.instance_variable_set :@site_path, site_path
|
213
|
+
Geb::Config.expects(:site_directory_has_config?).returns(true)
|
214
|
+
YAML.stubs(:load_file).returns({'output_dir' => output_dir})
|
215
|
+
|
216
|
+
config = Geb::Config.new(site)
|
217
|
+
|
218
|
+
assert_equal output_dir, config.output_dir
|
219
|
+
|
220
|
+
end # test "that the output directory is returned as config value if set"
|
221
|
+
|
222
|
+
test "that the assets directory is returned as default if not set" do
|
223
|
+
|
224
|
+
site = Geb::Site.new
|
225
|
+
site_path = File.join(File.dirname(__FILE__), "..", "files", "fake_site")
|
226
|
+
|
227
|
+
site.instance_variable_set :@site_path, site_path
|
228
|
+
Geb::Config.expects(:site_directory_has_config?).returns(true)
|
229
|
+
YAML.stubs(:load_file).returns({})
|
230
|
+
|
231
|
+
config = Geb::Config.new(site)
|
232
|
+
|
233
|
+
assert_equal Geb::Defaults::ASSETS_DIR, config.assets_dir
|
234
|
+
|
235
|
+
end # test "that the assets directory is returned as default if not set"
|
236
|
+
|
237
|
+
test "that the assets directory is returned as config value if set" do
|
238
|
+
|
239
|
+
site = Geb::Site.new
|
240
|
+
assets_dir = "assets"
|
241
|
+
site_path = File.join(File.dirname(__FILE__), "..", "files", "fake_site")
|
242
|
+
|
243
|
+
site.instance_variable_set :@site_path, site_path
|
244
|
+
Geb::Config.expects(:site_directory_has_config?).returns(true)
|
245
|
+
YAML.stubs(:load_file).returns({'assets_dir' => assets_dir})
|
246
|
+
|
247
|
+
config = Geb::Config.new(site)
|
248
|
+
|
249
|
+
assert_equal assets_dir, config.assets_dir
|
250
|
+
|
251
|
+
end # test "that the assets directory is returned as config value if set"
|
252
|
+
|
253
|
+
test "that page extensions are returned as default if not set" do
|
254
|
+
|
255
|
+
site = Geb::Site.new
|
256
|
+
site_path = File.join(File.dirname(__FILE__), "..", "files", "fake_site")
|
257
|
+
|
258
|
+
site.instance_variable_set :@site_path, site_path
|
259
|
+
Geb::Config.expects(:site_directory_has_config?).returns(true)
|
260
|
+
YAML.stubs(:load_file).returns({})
|
261
|
+
|
262
|
+
config = Geb::Config.new(site)
|
263
|
+
|
264
|
+
assert_equal Geb::Defaults::PAGE_EXTENSIONS, config.page_extensions
|
265
|
+
|
266
|
+
end # test "that page extensions are returned as default if not set"
|
267
|
+
|
268
|
+
test "that page extensions are returned as config value if set" do
|
269
|
+
|
270
|
+
site = Geb::Site.new
|
271
|
+
page_extensions = [".html", ".htm"]
|
272
|
+
site_path = File.join(File.dirname(__FILE__), "..", "files", "fake_site")
|
273
|
+
|
274
|
+
site.instance_variable_set :@site_path, site_path
|
275
|
+
Geb::Config.expects(:site_directory_has_config?).returns(true)
|
276
|
+
YAML.stubs(:load_file).returns({'page_extensions' => page_extensions})
|
277
|
+
|
278
|
+
config = Geb::Config.new(site)
|
279
|
+
|
280
|
+
assert_equal page_extensions, config.page_extensions
|
281
|
+
|
282
|
+
end # test "that page extensions are returned as config value if set"
|
283
|
+
|
284
|
+
test "that the template and partial identifier is returned as default if not set" do
|
285
|
+
|
286
|
+
site = Geb::Site.new
|
287
|
+
site_path = File.join(File.dirname(__FILE__), "..", "files", "fake_site")
|
288
|
+
|
289
|
+
site.instance_variable_set :@site_path, site_path
|
290
|
+
Geb::Config.expects(:site_directory_has_config?).returns(true)
|
291
|
+
YAML.stubs(:load_file).returns({})
|
292
|
+
|
293
|
+
config = Geb::Config.new(site)
|
294
|
+
|
295
|
+
assert_equal Geb::Defaults::TEMPLATE_AND_PARTIAL_IDENTIFIER, config.template_and_partial_identifier
|
296
|
+
|
297
|
+
end # test "that the template and partial identifier is returned as default if not set"
|
298
|
+
|
299
|
+
test "that the template paths are returned as empty array if not set" do
|
300
|
+
|
301
|
+
site = Geb::Site.new
|
302
|
+
site_path = File.join(File.dirname(__FILE__), "..", "files", "fake_site")
|
303
|
+
|
304
|
+
site.instance_variable_set :@site_path, site_path
|
305
|
+
Geb::Config.expects(:site_directory_has_config?).returns(true)
|
306
|
+
YAML.stubs(:load_file).returns({})
|
307
|
+
|
308
|
+
config = Geb::Config.new(site)
|
309
|
+
|
310
|
+
assert_empty config.template_paths
|
311
|
+
|
312
|
+
end # test "that the template paths are returned as empty array if not set"
|
313
|
+
|
314
|
+
test "that the template paths are returned as config value if set" do
|
315
|
+
|
316
|
+
site = Geb::Site.new
|
317
|
+
template_paths = ["templates", "partials"]
|
318
|
+
site_path = File.join(File.dirname(__FILE__), "..", "files", "fake_site")
|
319
|
+
|
320
|
+
site.instance_variable_set :@site_path, site_path
|
321
|
+
Geb::Config.expects(:site_directory_has_config?).returns(true)
|
322
|
+
YAML.stubs(:load_file).returns({'template_paths' => template_paths})
|
323
|
+
|
324
|
+
config = Geb::Config.new(site)
|
325
|
+
|
326
|
+
assert_equal template_paths, config.template_paths
|
327
|
+
|
328
|
+
end # test "that the template paths are returned as config value if set"
|
329
|
+
|
330
|
+
end # class TestConfig < Minitest::Test
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# Tests the defaults for the Geb gem.
|
4
|
+
#
|
5
|
+
# @title Geb - Test - Defaults
|
6
|
+
# @author Edin Mustajbegovic <edin@actiontwelve.com>
|
7
|
+
# @copyright 2024 Edin Mustajbegovic
|
8
|
+
# @license MIT
|
9
|
+
#
|
10
|
+
# @see https://github.com/mainfram-work/geb for more information
|
11
|
+
|
12
|
+
require "test_helper"
|
13
|
+
|
14
|
+
class TestDefaults < Minitest::Test
|
15
|
+
|
16
|
+
test "that all defaults have acceptable values" do
|
17
|
+
|
18
|
+
# step through all the defaults and make sure they are not nil
|
19
|
+
assert Geb::Defaults::TEMPLATE_ARCHIVE_FILENAME
|
20
|
+
assert Geb::Defaults::AVAILABLE_TEMPLATES
|
21
|
+
assert Geb::Defaults::SITE_CONFIG_FILENAME
|
22
|
+
assert Geb::Defaults::BUNDLED_TEMPLATES_DIR
|
23
|
+
assert Geb::Defaults::DEFAULT_TEMPLATE_DIR
|
24
|
+
assert Geb::Defaults::DEFAULT_TEMPLATE
|
25
|
+
assert Geb::Defaults::OUTPUT_DIR
|
26
|
+
assert Geb::Defaults::LOCAL_OUTPUT_DIR
|
27
|
+
assert Geb::Defaults::RELEASE_OUTPUT_DIR
|
28
|
+
assert Geb::Defaults::ASSETS_DIR
|
29
|
+
assert Geb::Defaults::PAGE_EXTENSIONS
|
30
|
+
assert Geb::Defaults::TEMPLATE_AND_PARTIAL_IDENTIFIER
|
31
|
+
|
32
|
+
# make sure all the defaults are of correct type
|
33
|
+
assert_instance_of String, Geb::Defaults::TEMPLATE_ARCHIVE_FILENAME
|
34
|
+
assert_instance_of Array, Geb::Defaults::AVAILABLE_TEMPLATES
|
35
|
+
assert_instance_of String, Geb::Defaults::SITE_CONFIG_FILENAME
|
36
|
+
assert_instance_of String, Geb::Defaults::BUNDLED_TEMPLATES_DIR
|
37
|
+
assert_instance_of String, Geb::Defaults::DEFAULT_TEMPLATE_DIR
|
38
|
+
assert_instance_of String, Geb::Defaults::DEFAULT_TEMPLATE
|
39
|
+
assert_instance_of String, Geb::Defaults::OUTPUT_DIR
|
40
|
+
assert_instance_of String, Geb::Defaults::LOCAL_OUTPUT_DIR
|
41
|
+
assert_instance_of String, Geb::Defaults::RELEASE_OUTPUT_DIR
|
42
|
+
assert_instance_of String, Geb::Defaults::ASSETS_DIR
|
43
|
+
assert_instance_of Array, Geb::Defaults::PAGE_EXTENSIONS
|
44
|
+
assert_instance_of Regexp, Geb::Defaults::TEMPLATE_AND_PARTIAL_IDENTIFIER
|
45
|
+
|
46
|
+
# make sure the defaults are not empty
|
47
|
+
refute_empty Geb::Defaults::TEMPLATE_ARCHIVE_FILENAME
|
48
|
+
refute_empty Geb::Defaults::AVAILABLE_TEMPLATES
|
49
|
+
refute_empty Geb::Defaults::SITE_CONFIG_FILENAME
|
50
|
+
refute_empty Geb::Defaults::BUNDLED_TEMPLATES_DIR
|
51
|
+
refute_empty Geb::Defaults::DEFAULT_TEMPLATE_DIR
|
52
|
+
refute_empty Geb::Defaults::DEFAULT_TEMPLATE
|
53
|
+
refute_empty Geb::Defaults::OUTPUT_DIR
|
54
|
+
refute_empty Geb::Defaults::LOCAL_OUTPUT_DIR
|
55
|
+
refute_empty Geb::Defaults::RELEASE_OUTPUT_DIR
|
56
|
+
refute_empty Geb::Defaults::ASSETS_DIR
|
57
|
+
refute_empty Geb::Defaults::PAGE_EXTENSIONS
|
58
|
+
refute_match Geb::Defaults::TEMPLATE_AND_PARTIAL_IDENTIFIER, ""
|
59
|
+
|
60
|
+
end # test "that all defaults have values"
|
61
|
+
|
62
|
+
end # class TestDefaults < Minitest::Test
|
@@ -0,0 +1,105 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# Tests the git class
|
4
|
+
#
|
5
|
+
# @title Geb - Test - Git
|
6
|
+
# @author Edin Mustajbegovic <edin@actiontwelve.com>
|
7
|
+
# @copyright 2024 Edin Mustajbegovic
|
8
|
+
# @license MIT
|
9
|
+
#
|
10
|
+
# @see https://github.com/mainfram-work/geb for more information
|
11
|
+
|
12
|
+
require "test_helper"
|
13
|
+
|
14
|
+
class GitTest < Geb::ApiTest
|
15
|
+
|
16
|
+
test "that git validation raises an error if given fake folder" do
|
17
|
+
|
18
|
+
assert_raises Geb::Git::FailedValidationError do
|
19
|
+
Geb::Git.validate_git_repo("/some/fake/folder/path")
|
20
|
+
end # assert_raises
|
21
|
+
|
22
|
+
end # test "that git validation raises an error if given fake folder"
|
23
|
+
|
24
|
+
test "that git validation raises an error if given a folder that already has a git repo" do
|
25
|
+
|
26
|
+
assert_raises Geb::Git::InsideGitRepoError do
|
27
|
+
Geb::Git.validate_git_repo(__dir__)
|
28
|
+
end # assert_raises
|
29
|
+
|
30
|
+
end # test "that git validation raises an error if given a folder that already has a git repo"
|
31
|
+
|
32
|
+
test "that git validation raises an error if any other error other then not a git repo is raised" do
|
33
|
+
|
34
|
+
capture3_status = mock()
|
35
|
+
capture3_status.stubs(:success?).returns(false)
|
36
|
+
|
37
|
+
Open3.expects(:capture3).returns(["", "", capture3_status]).once
|
38
|
+
|
39
|
+
Dir.mktmpdir do |temp_dir|
|
40
|
+
assert_raises Geb::Git::FailedValidationError do
|
41
|
+
Geb::Git.validate_git_repo(File.join(temp_dir, "test_dir5"))
|
42
|
+
end # assert_raises
|
43
|
+
end # Dir.mktmpdir
|
44
|
+
|
45
|
+
end # test "that git validation raises an error if any other error other then not a git repo is raised"
|
46
|
+
|
47
|
+
test "that git validation passes if given a valid path without any git repos" do
|
48
|
+
|
49
|
+
Dir.mktmpdir do |temp_dir|
|
50
|
+
Geb::Git.validate_git_repo(temp_dir)
|
51
|
+
end # Dir.mktmpdir
|
52
|
+
|
53
|
+
end # test "that git validation passes if given a valid path without any git repos"
|
54
|
+
|
55
|
+
test "that git create repo raises an error if git command fails" do
|
56
|
+
|
57
|
+
git_error_message = "Some very important git error"
|
58
|
+
|
59
|
+
capture3_status = mock()
|
60
|
+
capture3_status.stubs(:success?).returns(false)
|
61
|
+
|
62
|
+
Open3.expects(:capture3).returns(["", git_error_message, capture3_status]).once
|
63
|
+
|
64
|
+
error = assert_raises Geb::Git::GitError do
|
65
|
+
Geb::Git.create_git_repo("/some/fake/folder/path")
|
66
|
+
end # assert_raises
|
67
|
+
|
68
|
+
assert_includes error.message, git_error_message
|
69
|
+
|
70
|
+
end # test "that git create repo raises an error if git command fails"
|
71
|
+
|
72
|
+
test "that git create repo passes if git command succeeds" do
|
73
|
+
|
74
|
+
Dir.mktmpdir do |temp_dir|
|
75
|
+
|
76
|
+
Geb::Git.create_git_repo(temp_dir)
|
77
|
+
|
78
|
+
assert Dir.exist?(File.join(temp_dir, ".git"))
|
79
|
+
assert File.exist?(File.join(temp_dir, ".gitignore"))
|
80
|
+
|
81
|
+
end # Dir.mktmpdir
|
82
|
+
|
83
|
+
end # test "that git create repo passes if git command succeeds"
|
84
|
+
|
85
|
+
test "that git create repo raises an error if it fails to create .gitignore" do
|
86
|
+
|
87
|
+
file_error_message = "Some very important file error"
|
88
|
+
|
89
|
+
capture3_status = mock()
|
90
|
+
capture3_status.stubs(:success?).returns(true)
|
91
|
+
|
92
|
+
Open3.expects(:capture3).returns(["", "", capture3_status]).once
|
93
|
+
|
94
|
+
File.expects(:open).raises(Errno::EACCES, file_error_message)
|
95
|
+
|
96
|
+
error = assert_raises Geb::Git::GitError do
|
97
|
+
Geb::Git.create_git_repo("/some/fake/folder/path")
|
98
|
+
end # assert_raises
|
99
|
+
|
100
|
+
assert_includes error.message, "Could not create .gitignore file"
|
101
|
+
assert_includes error.message, file_error_message
|
102
|
+
|
103
|
+
end # test "that git create repo raises an error if it fails to create .gitignore"
|
104
|
+
|
105
|
+
end # class SiteTest < Minitest::Test
|