Skip to content

Commit 87b5841

Browse files
authored
#65 Fix regression related to require_relative and fix integration tests
2 parents f426bcf + 59018c7 commit 87b5841

File tree

6 files changed

+37
-17
lines changed

6 files changed

+37
-17
lines changed

Rakefile

+27-7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require "bundler/gem_tasks"
44
require "rspec/core/rake_task"
55
require "tty-prompt"
6+
require "tmpdir"
67

78
RSpec::Core::RakeTask.new(:spec)
89

@@ -14,21 +15,28 @@ task default: %i[spec rubocop]
1415

1516
desc "Generates Swift source code and run its unit tests."
1617
task :test_swift do
17-
sh("ARKANA_RUNNING_CI_INTEGRATION_TESTS=true bin/arkana --config-filepath spec/fixtures/swift-tests.yml --dotenv-filepath spec/fixtures/.env.fruitloops --include-environments dev,staging")
18-
Dir.chdir("tests/MySecrets") do
18+
config_file = File.absolute_path("spec/fixtures/swift-tests.yml")
19+
dotenv_file = File.absolute_path("spec/fixtures/.env.fruitloops")
20+
with_temp_dir do |temp_dir|
21+
puts "Current working directory: #{temp_dir}"
22+
sh("ARKANA_RUNNING_CI_INTEGRATION_TESTS=true arkana --config-filepath #{config_file} --dotenv-filepath #{dotenv_file} --include-environments dev,staging")
23+
Dir.chdir("tests/MySecrets")
1924
sh("swift test")
2025
end
21-
FileUtils.rm_rf("tests")
2226
end
2327

2428
desc "Generates Kotlin source code and run its unit tests."
2529
task :test_kotlin do
26-
FileUtils.copy_entry("spec/fixtures/kotlin", "tests")
27-
sh("ARKANA_RUNNING_CI_INTEGRATION_TESTS=true bin/arkana --lang kotlin --config-filepath spec/fixtures/kotlin-tests.yml --dotenv-filepath spec/fixtures/.env.fruitloops --include-environments dev,staging")
28-
Dir.chdir("tests") do
30+
config_file = File.absolute_path("spec/fixtures/kotlin-tests.yml")
31+
dotenv_file = File.absolute_path("spec/fixtures/.env.fruitloops")
32+
directory_to_copy = File.absolute_path("spec/fixtures/kotlin")
33+
with_temp_dir do |temp_dir|
34+
puts "Current working directory: #{temp_dir}"
35+
FileUtils.copy_entry(directory_to_copy, "tests")
36+
sh("ARKANA_RUNNING_CI_INTEGRATION_TESTS=true arkana --lang kotlin --config-filepath #{config_file} --dotenv-filepath #{dotenv_file} --include-environments dev,staging")
37+
Dir.chdir("tests")
2938
sh("./gradlew test")
3039
end
31-
FileUtils.rm_rf("tests")
3240
end
3341

3442
desc "Sets lib version to the semantic version given, and push it to remote."
@@ -45,3 +53,15 @@ task :bump, [:v] do |_t, args|
4553
sh("git commit -m 'Bump app version to v#{version}.'")
4654
sh("git push origin")
4755
end
56+
57+
# Utilities
58+
59+
# Run tests in a different folder because when running in the same root folder as the gem,
60+
# there can be "relative_require" that happen to work in the test but wouldn't work when installing the gem in a different project.
61+
def with_temp_dir
62+
Dir.mktmpdir do |temp_dir|
63+
Dir.chdir(temp_dir) do
64+
yield temp_dir
65+
end
66+
end
67+
end

lib/arkana/templates/kotlin/arkana.kt.erb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
<% require_relative "lib/arkana/helpers/string" %>
2-
<% require_relative "lib/arkana/helpers/kotlin_template_helper" %>
1+
<% require "arkana/helpers/string" %>
2+
<% require "arkana/helpers/kotlin_template_helper" %>
33
<% # TODO: Sort these import statements alphabetically %>
44
// DO NOT MODIFY
55
// Automatically generated by Arkana (https://github.com/rogerluan/arkana)

lib/arkana/templates/kotlin/arkana_protocol.kt.erb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
<% require_relative "lib/arkana/helpers/string" %>
2-
<% require_relative "lib/arkana/helpers/kotlin_template_helper" %>
1+
<% require "arkana/helpers/string" %>
2+
<% require "arkana/helpers/kotlin_template_helper" %>
33
// DO NOT MODIFY
44
// Automatically generated by Arkana (https://github.com/rogerluan/arkana)
55
package <%= @kotlin_package_name %>

lib/arkana/templates/kotlin/arkana_tests.kt.erb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
<% require_relative "lib/arkana/helpers/string" %>
2-
<% require_relative "lib/arkana/helpers/kotlin_template_helper" %>
1+
<% require "arkana/helpers/string" %>
2+
<% require "arkana/helpers/kotlin_template_helper" %>
33
// DO NOT MODIFY
44
// Automatically generated by Arkana (https://github.com/rogerluan/arkana)
55
package <%= @kotlin_package_name %>

lib/arkana/templates/swift/arkana.swift.erb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
<% require_relative "lib/arkana/helpers/string" %>
2-
<% require_relative "lib/arkana/helpers/swift_template_helper" %>
1+
<% require "arkana/helpers/string" %>
2+
<% require "arkana/helpers/swift_template_helper" %>
33
<% # TODO: Sort these import statements alphabetically %>
44
// DO NOT MODIFY
55
// Automatically generated by Arkana (https://github.com/rogerluan/arkana)

lib/arkana/templates/swift/arkana_protocol.swift.erb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
<% require_relative "lib/arkana/helpers/string" %>
2-
<% require_relative "lib/arkana/helpers/swift_template_helper" %>
1+
<% require "arkana/helpers/string" %>
2+
<% require "arkana/helpers/swift_template_helper" %>
33
// DO NOT MODIFY
44
// Automatically generated by Arkana (https://github.com/rogerluan/arkana)
55

0 commit comments

Comments
 (0)