3
3
require "bundler/gem_tasks"
4
4
require "rspec/core/rake_task"
5
5
require "tty-prompt"
6
+ require "tmpdir"
6
7
7
8
RSpec ::Core ::RakeTask . new ( :spec )
8
9
@@ -14,21 +15,28 @@ task default: %i[spec rubocop]
14
15
15
16
desc "Generates Swift source code and run its unit tests."
16
17
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" )
19
24
sh ( "swift test" )
20
25
end
21
- FileUtils . rm_rf ( "tests" )
22
26
end
23
27
24
28
desc "Generates Kotlin source code and run its unit tests."
25
29
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" )
29
38
sh ( "./gradlew test" )
30
39
end
31
- FileUtils . rm_rf ( "tests" )
32
40
end
33
41
34
42
desc "Sets lib version to the semantic version given, and push it to remote."
@@ -45,3 +53,15 @@ task :bump, [:v] do |_t, args|
45
53
sh ( "git commit -m 'Bump app version to v#{ version } .'" )
46
54
sh ( "git push origin" )
47
55
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
0 commit comments