From 9589e74c1d2b1f20be1f87aafa4ee066760ab6fa Mon Sep 17 00:00:00 2001 From: Loren Segal Date: Fri, 3 Aug 2018 20:53:01 -0700 Subject: [PATCH] Fix test compat with RubyGems in Ruby 2.5+ Fixes #1161 --- spec/cli/server_spec.rb | 4 ++++ spec/cli/yri_spec.rb | 14 ++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/spec/cli/server_spec.rb b/spec/cli/server_spec.rb index 523ded757..89337bf74 100644 --- a/spec/cli/server_spec.rb +++ b/spec/cli/server_spec.rb @@ -85,6 +85,10 @@ def mock_file(filename, content = nil) mock_file(filename_e) unless filename_e == filename end + before :each do + allow(File).to receive(:exist?).and_call_original + end + context 'when .yardopts file exists' do before :each do Registry.yardoc_file = Registry::DEFAULT_YARDOC_FILE diff --git a/spec/cli/yri_spec.rb b/spec/cli/yri_spec.rb index a701392c6..d151bc5bd 100644 --- a/spec/cli/yri_spec.rb +++ b/spec/cli/yri_spec.rb @@ -46,9 +46,10 @@ def print_object(*args) test_stub; super end describe "#initialize" do it "loads search paths" do path = %r{/\.yard/yri_search_paths$} - expect(File).to receive(:file?).with(%r{/\.yard/yri_cache$}).and_return(false) - expect(File).to receive(:file?).with(path).and_return(true) - expect(File).to receive(:readlines).with(path).and_return(%w(line1 line2)) + allow(File).to receive(:file?).and_call_original + allow(File).to receive(:file?).with(%r{/\.yard/yri_cache$}).and_return(false) + allow(File).to receive(:file?).with(path).and_return(true) + allow(File).to receive(:readlines).with(path).and_return(%w(line1 line2)) @yri = YARD::CLI::YRI.new spaths = @yri.instance_variable_get("@search_paths") expect(spaths).to include('line1') @@ -58,9 +59,10 @@ def print_object(*args) test_stub; super end it "uses DEFAULT_SEARCH_PATHS prior to other paths" do YARD::CLI::YRI::DEFAULT_SEARCH_PATHS.push('foo', 'bar') path = %r{/\.yard/yri_search_paths$} - expect(File).to receive(:file?).with(%r{/\.yard/yri_cache$}).and_return(false) - expect(File).to receive(:file?).with(path).and_return(true) - expect(File).to receive(:readlines).with(path).and_return(%w(line1 line2)) + allow(File).to receive(:file?).and_call_original + allow(File).to receive(:file?).with(%r{/\.yard/yri_cache$}).and_return(false) + allow(File).to receive(:file?).with(path).and_return(true) + allow(File).to receive(:readlines).with(path).and_return(%w(line1 line2)) @yri = YARD::CLI::YRI.new spaths = @yri.instance_variable_get("@search_paths") expect(spaths[0, 4]).to eq %w(foo bar line1 line2)