From d8e61aba482fe3167e6399a888763ce2a796b30d Mon Sep 17 00:00:00 2001 From: Anton Rieder <1301152+aried3r@users.noreply.github.com> Date: Tue, 7 Jan 2020 11:43:23 +0100 Subject: [PATCH] Updating Ruby versions on Travis CI (#30) * Adding Ruby 2.7 * Removing EOL Ruby versions * Adding `MemFs.ruby_version_gte?` and `MemFs.windows?` * Implementing `MemFs::Dir#children` * Adding Ruby 2.7 `File::extname` behavior variant --- .travis.yml | 12 +++++------- lib/memfs.rb | 8 ++++++++ lib/memfs/dir.rb | 6 ++++++ spec/fileutils_spec.rb | 10 ++++++++-- spec/memfs/dir_spec.rb | 16 ++++++++++++++++ spec/memfs/file_spec.rb | 13 ++++++++++--- 6 files changed, 53 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index d4a8695..97ab780 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,7 @@ -# before_install: -# - gem update --system '2.4.5' language: ruby +cache: bundler rvm: - - 2.0.0 - - 2.1.10 - - 2.2.5 - - 2.3.3 - - 2.4.0 + - 2.4 + - 2.5 + - 2.6 + - 2.7 diff --git a/lib/memfs.rb b/lib/memfs.rb index 0912307..adf132b 100644 --- a/lib/memfs.rb +++ b/lib/memfs.rb @@ -25,6 +25,14 @@ module MemFs # Keeps track of the original Ruby IO class. OriginalIO = ::IO + def self.ruby_version_gte?(version) # :nodoc: + Gem::Version.new(RUBY_VERSION) >= Gem::Version.new(version) + end + + def self.windows? + /mswin|bccwin|mingw/ =~ RUBY_PLATFORM + end + require 'memfs/file_system' require 'memfs/dir' require 'memfs/file' diff --git a/lib/memfs/dir.rb b/lib/memfs/dir.rb index 30e1b84..82fb61b 100644 --- a/lib/memfs/dir.rb +++ b/lib/memfs/dir.rb @@ -17,6 +17,12 @@ def self.chdir(path, &block) 0 end + if MemFs.ruby_version_gte?('2.6') + def self.children(dirname, _opts = {}) + entries(dirname, _opts) - %w[. ..] + end + end + def self.chroot(path) fail Errno::EPERM, path unless Process.uid.zero? diff --git a/spec/fileutils_spec.rb b/spec/fileutils_spec.rb index 890e7d6..c66d48f 100644 --- a/spec/fileutils_spec.rb +++ b/spec/fileutils_spec.rb @@ -20,8 +20,14 @@ expect(described_class.pwd).to eq('/test') end - it 'returns nil' do - expect(described_class.cd('/test')).to be_nil + if MemFs.ruby_version_gte?('2.6') + it 'returns 0' do + expect(described_class.cd('/test')).to eq 0 + end + else + it 'returns nil' do + expect(described_class.cd('/test')).to be_nil + end end it "raises an error when the given path doesn't exist" do diff --git a/spec/memfs/dir_spec.rb b/spec/memfs/dir_spec.rb index ef21919..c12e0e8 100644 --- a/spec/memfs/dir_spec.rb +++ b/spec/memfs/dir_spec.rb @@ -54,6 +54,22 @@ module MemFs end end + if MemFs.ruby_version_gte?('2.6') + describe '.children' do + it 'returns an array containing all of the filenames except for "." and ".." in this directory.' do + %w[/test/dir1 /test/dir2].each { |dir| described_class.mkdir dir } + _fs.touch '/test/file1', '/test/file2' + expect(described_class.children('/test')).to eq(%w[dir1 dir2 file1 file2]) + end + end + else + describe '.children' do + it 'raises an error' do + expect { described_class.children('/test') }.to raise_error(NoMethodError) + end + end + end + describe '.chroot' do before { allow(Process).to receive_messages(uid: 0) } diff --git a/spec/memfs/file_spec.rb b/spec/memfs/file_spec.rb index f594d8e..9d28fe1 100644 --- a/spec/memfs/file_spec.rb +++ b/spec/memfs/file_spec.rb @@ -527,9 +527,16 @@ module MemFs end context 'when the period is the last character in path' do - it 'returns an empty string' do - extname = described_class.extname('test-subject.') - expect(extname).to eq '' + if MemFs.ruby_version_gte?('2.7') && !MemFs.windows? + it 'returns a period' do + extname = described_class.extname('test-subject.') + expect(extname).to eq '.' + end + else + it 'returns an empty string' do + extname = described_class.extname('test-subject.') + expect(extname).to eq '' + end end end end