diff --git a/lib/core/config.rb b/lib/core/config.rb index 53e91041..dbc2e606 100644 --- a/lib/core/config.rb +++ b/lib/core/config.rb @@ -138,10 +138,12 @@ def load_apps # rubocop:disable Metrics/MethodLength ensure_current_config_app!(app) if app end - def find_app_config_file + def config_file_path + return @config_file_path if @config_file_path + path = Pathname.new(".").expand_path - loop do + @config_file_path = loop do config_file = path + CONFIG_FILE_LOCATIION break config_file if File.file?(config_file) @@ -153,10 +155,6 @@ def find_app_config_file end end - def config_file_path - @config_file_path ||= find_app_config_file - end - def new_option_keys { org: :cpln_org, diff --git a/spec/command/cleanup_images_spec.rb b/spec/command/cleanup_images_spec.rb index 1b540a38..73fd3dfe 100644 --- a/spec/command/cleanup_images_spec.rb +++ b/spec/command/cleanup_images_spec.rb @@ -7,7 +7,7 @@ allow(ENV).to receive(:fetch).with("CPLN_ENDPOINT", "https://api.cpln.io").and_return("https://api.cpln.io") allow(ENV).to receive(:fetch).with("CPLN_TOKEN", nil).and_return("token") allow(ENV).to receive(:fetch).with("CPLN_ORG", nil).and_return(nil) - allow_any_instance_of(Config).to receive(:find_app_config_file).and_return("spec/fixtures/config.yml") # rubocop:disable RSpec/AnyInstance + allow_any_instance_of(Config).to receive(:config_file_path).and_return("spec/fixtures/config.yml") # rubocop:disable RSpec/AnyInstance Timecop.freeze(Time.local(2023, 8, 23)) end diff --git a/spec/command/copy_image_from_upstream_spec.rb b/spec/command/copy_image_from_upstream_spec.rb index 270593f1..5d104865 100644 --- a/spec/command/copy_image_from_upstream_spec.rb +++ b/spec/command/copy_image_from_upstream_spec.rb @@ -8,7 +8,7 @@ allow(ENV).to receive(:fetch).with("CPLN_ENDPOINT", "https://api.cpln.io").and_return("https://api.cpln.io") allow(ENV).to receive(:fetch).with("CPLN_TOKEN", nil).and_return("token") allow(ENV).to receive(:fetch).with("CPLN_ORG", nil).and_return(nil) - allow_any_instance_of(Config).to receive(:find_app_config_file).and_return("spec/fixtures/config.yml") + allow_any_instance_of(Config).to receive(:config_file_path).and_return("spec/fixtures/config.yml") allow_any_instance_of(described_class).to receive(:ensure_docker_running!) allow_any_instance_of(Controlplane).to receive(:profile_exists?).and_return(false) allow_any_instance_of(Controlplane).to receive(:profile_create).and_return(true) diff --git a/spec/command/maintenance_off_spec.rb b/spec/command/maintenance_off_spec.rb index 01e3bb71..5010cb33 100644 --- a/spec/command/maintenance_off_spec.rb +++ b/spec/command/maintenance_off_spec.rb @@ -8,7 +8,7 @@ allow(ENV).to receive(:fetch).with("CPLN_ENDPOINT", "https://api.cpln.io").and_return("https://api.cpln.io") allow(ENV).to receive(:fetch).with("CPLN_TOKEN", nil).and_return("token") allow(ENV).to receive(:fetch).with("CPLN_ORG", nil).and_return(nil) - allow_any_instance_of(Config).to receive(:find_app_config_file).and_return("spec/fixtures/config.yml") + allow_any_instance_of(Config).to receive(:config_file_path).and_return("spec/fixtures/config.yml") allow_any_instance_of(described_class).to receive(:sleep).and_return(true) end # rubocop:enable RSpec/AnyInstance diff --git a/spec/command/maintenance_on_spec.rb b/spec/command/maintenance_on_spec.rb index 455a6007..8e5f78b3 100644 --- a/spec/command/maintenance_on_spec.rb +++ b/spec/command/maintenance_on_spec.rb @@ -8,7 +8,7 @@ allow(ENV).to receive(:fetch).with("CPLN_ENDPOINT", "https://api.cpln.io").and_return("https://api.cpln.io") allow(ENV).to receive(:fetch).with("CPLN_TOKEN", nil).and_return("token") allow(ENV).to receive(:fetch).with("CPLN_ORG", nil).and_return(nil) - allow_any_instance_of(Config).to receive(:find_app_config_file).and_return("spec/fixtures/config.yml") + allow_any_instance_of(Config).to receive(:config_file_path).and_return("spec/fixtures/config.yml") allow_any_instance_of(described_class).to receive(:sleep).and_return(true) end # rubocop:enable RSpec/AnyInstance diff --git a/spec/command/maintenance_set_page_spec.rb b/spec/command/maintenance_set_page_spec.rb index 33781992..d2314e81 100644 --- a/spec/command/maintenance_set_page_spec.rb +++ b/spec/command/maintenance_set_page_spec.rb @@ -7,7 +7,7 @@ allow(ENV).to receive(:fetch).with("CPLN_ENDPOINT", "https://api.cpln.io").and_return("https://api.cpln.io") allow(ENV).to receive(:fetch).with("CPLN_TOKEN", nil).and_return("token") allow(ENV).to receive(:fetch).with("CPLN_ORG", nil).and_return(nil) - allow_any_instance_of(Config).to receive(:find_app_config_file).and_return("spec/fixtures/config.yml") # rubocop:disable RSpec/AnyInstance + allow_any_instance_of(Config).to receive(:config_file_path).and_return("spec/fixtures/config.yml") # rubocop:disable RSpec/AnyInstance end it "displays error if maintenance workload is not found", vcr: true do diff --git a/spec/command/maintenance_spec.rb b/spec/command/maintenance_spec.rb index c0b6b4f1..3cb97a97 100644 --- a/spec/command/maintenance_spec.rb +++ b/spec/command/maintenance_spec.rb @@ -7,7 +7,7 @@ allow(ENV).to receive(:fetch).with("CPLN_ENDPOINT", "https://api.cpln.io").and_return("https://api.cpln.io") allow(ENV).to receive(:fetch).with("CPLN_TOKEN", nil).and_return("token") allow(ENV).to receive(:fetch).with("CPLN_ORG", nil).and_return(nil) - allow_any_instance_of(Config).to receive(:find_app_config_file).and_return("spec/fixtures/config.yml") # rubocop:disable RSpec/AnyInstance + allow_any_instance_of(Config).to receive(:config_file_path).and_return("spec/fixtures/config.yml") # rubocop:disable RSpec/AnyInstance end it "displays error if domain is not found", vcr: true do diff --git a/spec/command/run_cleanup_spec.rb b/spec/command/run_cleanup_spec.rb index 6cc1219d..e6748d25 100644 --- a/spec/command/run_cleanup_spec.rb +++ b/spec/command/run_cleanup_spec.rb @@ -7,7 +7,7 @@ allow(ENV).to receive(:fetch).with("CPLN_ENDPOINT", "https://api.cpln.io").and_return("https://api.cpln.io") allow(ENV).to receive(:fetch).with("CPLN_TOKEN", nil).and_return("token") allow(ENV).to receive(:fetch).with("CPLN_ORG", nil).and_return(nil) - allow_any_instance_of(Config).to receive(:find_app_config_file).and_return("spec/fixtures/config.yml") # rubocop:disable RSpec/AnyInstance + allow_any_instance_of(Config).to receive(:config_file_path).and_return("spec/fixtures/config.yml") # rubocop:disable RSpec/AnyInstance Timecop.freeze(Time.local(2023, 5, 15)) end diff --git a/spec/cpl_spec.rb b/spec/cpl_spec.rb index 03dd2133..931fb46f 100644 --- a/spec/cpl_spec.rb +++ b/spec/cpl_spec.rb @@ -19,7 +19,7 @@ end end - allow_any_instance_of(Config).to receive(:find_app_config_file).and_return("spec/fixtures/config.yml") # rubocop:disable RSpec/AnyInstance + allow_any_instance_of(Config).to receive(:config_file_path).and_return("spec/fixtures/config.yml") # rubocop:disable RSpec/AnyInstance expect_any_instance_of(command_class).to receive(:call) # rubocop:disable RSpec/AnyInstance Cpl::Cli.start([command_class::NAME, *args]) @@ -39,7 +39,7 @@ allow(Config).to receive(:new).with([], { option[:name].to_sym => option_value }).and_call_original - allow_any_instance_of(Config).to receive(:find_app_config_file).and_return("spec/fixtures/config.yml") # rubocop:disable RSpec/AnyInstance + allow_any_instance_of(Config).to receive(:config_file_path).and_return("spec/fixtures/config.yml") # rubocop:disable RSpec/AnyInstance expect_any_instance_of(Command::Test).to receive(:call) # rubocop:disable RSpec/AnyInstance Cpl::Cli.start(["test", *args])