Skip to content

Commit

Permalink
Fix test compat with RubyGems in Ruby 2.5+
Browse files Browse the repository at this point in the history
Fixes #1161
  • Loading branch information
lsegal committed Aug 4, 2018
1 parent 8a0e6ac commit 9589e74
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 4 additions & 0 deletions spec/cli/server_spec.rb
Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions spec/cli/yri_spec.rb
Expand Up @@ -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')
Expand All @@ -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)
Expand Down

0 comments on commit 9589e74

Please sign in to comment.