diff --git a/Rakefile b/Rakefile index d548431..5f46fd7 100644 --- a/Rakefile +++ b/Rakefile @@ -3,6 +3,7 @@ require "bundler/gem_tasks" require "rspec/core/rake_task" require "tty-prompt" +require "tmpdir" RSpec::Core::RakeTask.new(:spec) @@ -14,21 +15,28 @@ task default: %i[spec rubocop] desc "Generates Swift source code and run its unit tests." task :test_swift do - 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") - Dir.chdir("tests/MySecrets") do + config_file = File.absolute_path("spec/fixtures/swift-tests.yml") + dotenv_file = File.absolute_path("spec/fixtures/.env.fruitloops") + with_temp_dir do |temp_dir| + puts "Current working directory: #{temp_dir}" + sh("ARKANA_RUNNING_CI_INTEGRATION_TESTS=true arkana --config-filepath #{config_file} --dotenv-filepath #{dotenv_file} --include-environments dev,staging") + Dir.chdir("tests/MySecrets") sh("swift test") end - FileUtils.rm_rf("tests") end desc "Generates Kotlin source code and run its unit tests." task :test_kotlin do - FileUtils.copy_entry("spec/fixtures/kotlin", "tests") - 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") - Dir.chdir("tests") do + config_file = File.absolute_path("spec/fixtures/kotlin-tests.yml") + dotenv_file = File.absolute_path("spec/fixtures/.env.fruitloops") + directory_to_copy = File.absolute_path("spec/fixtures/kotlin") + with_temp_dir do |temp_dir| + puts "Current working directory: #{temp_dir}" + FileUtils.copy_entry(directory_to_copy, "tests") + sh("ARKANA_RUNNING_CI_INTEGRATION_TESTS=true arkana --lang kotlin --config-filepath #{config_file} --dotenv-filepath #{dotenv_file} --include-environments dev,staging") + Dir.chdir("tests") sh("./gradlew test") end - FileUtils.rm_rf("tests") end desc "Sets lib version to the semantic version given, and push it to remote." @@ -45,3 +53,15 @@ task :bump, [:v] do |_t, args| sh("git commit -m 'Bump app version to v#{version}.'") sh("git push origin") end + +# Utilities + +# Run tests in a different folder because when running in the same root folder as the gem, +# there can be "relative_require" that happen to work in the test but wouldn't work when installing the gem in a different project. +def with_temp_dir + Dir.mktmpdir do |temp_dir| + Dir.chdir(temp_dir) do + yield temp_dir + end + end +end diff --git a/lib/arkana/templates/kotlin/arkana.kt.erb b/lib/arkana/templates/kotlin/arkana.kt.erb index bf3a575..7cd0927 100644 --- a/lib/arkana/templates/kotlin/arkana.kt.erb +++ b/lib/arkana/templates/kotlin/arkana.kt.erb @@ -1,5 +1,5 @@ -<% require_relative "lib/arkana/helpers/string" %> -<% require_relative "lib/arkana/helpers/kotlin_template_helper" %> +<% require "arkana/helpers/string" %> +<% require "arkana/helpers/kotlin_template_helper" %> <% # TODO: Sort these import statements alphabetically %> // DO NOT MODIFY // Automatically generated by Arkana (https://github.com/rogerluan/arkana) diff --git a/lib/arkana/templates/kotlin/arkana_protocol.kt.erb b/lib/arkana/templates/kotlin/arkana_protocol.kt.erb index 71dc054..1d313dc 100644 --- a/lib/arkana/templates/kotlin/arkana_protocol.kt.erb +++ b/lib/arkana/templates/kotlin/arkana_protocol.kt.erb @@ -1,5 +1,5 @@ -<% require_relative "lib/arkana/helpers/string" %> -<% require_relative "lib/arkana/helpers/kotlin_template_helper" %> +<% require "arkana/helpers/string" %> +<% require "arkana/helpers/kotlin_template_helper" %> // DO NOT MODIFY // Automatically generated by Arkana (https://github.com/rogerluan/arkana) package <%= @kotlin_package_name %> diff --git a/lib/arkana/templates/kotlin/arkana_tests.kt.erb b/lib/arkana/templates/kotlin/arkana_tests.kt.erb index a4666c4..fc2ce09 100644 --- a/lib/arkana/templates/kotlin/arkana_tests.kt.erb +++ b/lib/arkana/templates/kotlin/arkana_tests.kt.erb @@ -1,5 +1,5 @@ -<% require_relative "lib/arkana/helpers/string" %> -<% require_relative "lib/arkana/helpers/kotlin_template_helper" %> +<% require "arkana/helpers/string" %> +<% require "arkana/helpers/kotlin_template_helper" %> // DO NOT MODIFY // Automatically generated by Arkana (https://github.com/rogerluan/arkana) package <%= @kotlin_package_name %> diff --git a/lib/arkana/templates/swift/arkana.swift.erb b/lib/arkana/templates/swift/arkana.swift.erb index ecbc8f9..f03cebd 100644 --- a/lib/arkana/templates/swift/arkana.swift.erb +++ b/lib/arkana/templates/swift/arkana.swift.erb @@ -1,5 +1,5 @@ -<% require_relative "lib/arkana/helpers/string" %> -<% require_relative "lib/arkana/helpers/swift_template_helper" %> +<% require "arkana/helpers/string" %> +<% require "arkana/helpers/swift_template_helper" %> <% # TODO: Sort these import statements alphabetically %> // DO NOT MODIFY // Automatically generated by Arkana (https://github.com/rogerluan/arkana) diff --git a/lib/arkana/templates/swift/arkana_protocol.swift.erb b/lib/arkana/templates/swift/arkana_protocol.swift.erb index b4ca10a..2f72e06 100644 --- a/lib/arkana/templates/swift/arkana_protocol.swift.erb +++ b/lib/arkana/templates/swift/arkana_protocol.swift.erb @@ -1,5 +1,5 @@ -<% require_relative "lib/arkana/helpers/string" %> -<% require_relative "lib/arkana/helpers/swift_template_helper" %> +<% require "arkana/helpers/string" %> +<% require "arkana/helpers/swift_template_helper" %> // DO NOT MODIFY // Automatically generated by Arkana (https://github.com/rogerluan/arkana)