From 053efa99a74fee353aee64d3cfc4094ea40e1e6b Mon Sep 17 00:00:00 2001 From: Hans de Graaff Date: Fri, 12 Aug 2022 11:20:21 +0200 Subject: [PATCH 1/2] fix: convert File.exists? to File.exist? File.exists? is deprecated and issues warning messages when run. One instance was already updates in f4973b4ab172d222df57972780935d4fa47ef730 for #1211. This commit updates the remaining use of File.exists? --- lib/thinking_sphinx/commands/clear_real_time.rb | 2 +- lib/thinking_sphinx/settings.rb | 2 +- spec/support/sphinx_yaml_helpers.rb | 2 +- spec/thinking_sphinx/commands/clear_real_time_spec.rb | 2 +- spec/thinking_sphinx/commands/clear_sql_spec.rb | 2 +- spec/thinking_sphinx/configuration_spec.rb | 6 +++--- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/thinking_sphinx/commands/clear_real_time.rb b/lib/thinking_sphinx/commands/clear_real_time.rb index d43aa52ce..c9a71b474 100644 --- a/lib/thinking_sphinx/commands/clear_real_time.rb +++ b/lib/thinking_sphinx/commands/clear_real_time.rb @@ -7,7 +7,7 @@ def call Dir["#{index.path}.*"].each { |path| FileUtils.rm path } end - FileUtils.rm_r(binlog_path) if File.exists?(binlog_path) + FileUtils.rm_r(binlog_path) if File.exist?(binlog_path) end private diff --git a/lib/thinking_sphinx/settings.rb b/lib/thinking_sphinx/settings.rb index c6feadf20..cc87bc374 100644 --- a/lib/thinking_sphinx/settings.rb +++ b/lib/thinking_sphinx/settings.rb @@ -35,7 +35,7 @@ def initialize(configuration) end def call - return defaults unless File.exists? file + return defaults unless File.exist? file merged.inject({}) do |hash, (key, value)| if absolute_key?(key) diff --git a/spec/support/sphinx_yaml_helpers.rb b/spec/support/sphinx_yaml_helpers.rb index a344a45cf..def77b1b1 100644 --- a/spec/support/sphinx_yaml_helpers.rb +++ b/spec/support/sphinx_yaml_helpers.rb @@ -2,7 +2,7 @@ module SphinxYamlHelpers def write_configuration(hash) - allow(File).to receive_messages :read => {'test' => hash}.to_yaml, :exists? => true + allow(File).to receive_messages :read => {'test' => hash}.to_yaml, :exist? => true, :exists? => true end end diff --git a/spec/thinking_sphinx/commands/clear_real_time_spec.rb b/spec/thinking_sphinx/commands/clear_real_time_spec.rb index 2590a6947..7c09a4360 100644 --- a/spec/thinking_sphinx/commands/clear_real_time_spec.rb +++ b/spec/thinking_sphinx/commands/clear_real_time_spec.rb @@ -19,7 +19,7 @@ allow(FileUtils).to receive_messages :rm_r => true, :rm => true - allow(File).to receive_messages :exists? => true + allow(File).to receive_messages :exist? => true end it 'finds each file for real-time indices' do diff --git a/spec/thinking_sphinx/commands/clear_sql_spec.rb b/spec/thinking_sphinx/commands/clear_sql_spec.rb index 732ce3e2e..38fab2b3c 100644 --- a/spec/thinking_sphinx/commands/clear_sql_spec.rb +++ b/spec/thinking_sphinx/commands/clear_sql_spec.rb @@ -25,7 +25,7 @@ and_return(['/path/to/indices/ts-foo.tmp']) allow(FileUtils).to receive_messages :rm_r => true, :rm => true - allow(File).to receive_messages :exists? => true + allow(File).to receive_messages :exist? => true end it 'finds each file for sql-backed indices' do diff --git a/spec/thinking_sphinx/configuration_spec.rb b/spec/thinking_sphinx/configuration_spec.rb index b5da2aee5..0cbf7c814 100644 --- a/spec/thinking_sphinx/configuration_spec.rb +++ b/spec/thinking_sphinx/configuration_spec.rb @@ -38,7 +38,7 @@ def expect_loading_of(file) end it 'does not cache settings after reset' do - allow(File).to receive_messages :exists? => true + allow(File).to receive_messages :exist? => true allow(File).to receive_messages :read => { 'test' => {'foo' => 'bugs'}, 'production' => {'foo' => 'bar'} @@ -504,7 +504,7 @@ def expect_loading_of(file) describe '#settings' do context 'YAML file exists' do before :each do - allow(File).to receive_messages :exists? => true + allow(File).to receive_messages :exist? => true end it "reads from the YAML file" do @@ -540,7 +540,7 @@ def expect_loading_of(file) context 'YAML file does not exist' do before :each do - allow(File).to receive_messages :exists? => false + allow(File).to receive_messages :exist? => false end it "does not read the file" do From 1894089d6a45759b7e3150eb9ef030916d992851 Mon Sep 17 00:00:00 2001 From: Pat Allan Date: Tue, 6 Sep 2022 21:28:42 +1000 Subject: [PATCH 2/2] fix: Keep File.exist? stubs focused. Use the original implementation for everything but the specific path that matters. --- spec/support/sphinx_yaml_helpers.rb | 7 ++++++- spec/thinking_sphinx/configuration_spec.rb | 19 ++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/spec/support/sphinx_yaml_helpers.rb b/spec/support/sphinx_yaml_helpers.rb index def77b1b1..442fd5c68 100644 --- a/spec/support/sphinx_yaml_helpers.rb +++ b/spec/support/sphinx_yaml_helpers.rb @@ -2,7 +2,12 @@ module SphinxYamlHelpers def write_configuration(hash) - allow(File).to receive_messages :read => {'test' => hash}.to_yaml, :exist? => true, :exists? => true + allow(File).to receive(:read).and_return({'test' => hash}.to_yaml) + allow(File).to receive(:exist?).and_wrap_original do |original, path| + next true if path.to_s == File.absolute_path("config/thinking_sphinx.yml", Rails.root.to_s) + + original.call(path) + end end end diff --git a/spec/thinking_sphinx/configuration_spec.rb b/spec/thinking_sphinx/configuration_spec.rb index 0cbf7c814..b7c9df672 100644 --- a/spec/thinking_sphinx/configuration_spec.rb +++ b/spec/thinking_sphinx/configuration_spec.rb @@ -38,7 +38,12 @@ def expect_loading_of(file) end it 'does not cache settings after reset' do - allow(File).to receive_messages :exist? => true + allow(File).to receive(:exist?).and_wrap_original do |original, path| + next true if path.to_s == File.absolute_path("config/thinking_sphinx.yml", Rails.root) + + original.call(path) + end + allow(File).to receive_messages :read => { 'test' => {'foo' => 'bugs'}, 'production' => {'foo' => 'bar'} @@ -504,7 +509,11 @@ def expect_loading_of(file) describe '#settings' do context 'YAML file exists' do before :each do - allow(File).to receive_messages :exist? => true + allow(File).to receive(:exist?).and_wrap_original do |original, path| + next true if path.to_s == File.absolute_path("config/thinking_sphinx.yml", Rails.root) + + original.call(path) + end end it "reads from the YAML file" do @@ -540,7 +549,11 @@ def expect_loading_of(file) context 'YAML file does not exist' do before :each do - allow(File).to receive_messages :exist? => false + allow(File).to receive(:exist?).and_wrap_original do |original, path| + next false if path.to_s == File.absolute_path("config/thinking_sphinx.yml", Rails.root) + + original.call(path) + end end it "does not read the file" do