Skip to content

Commit

Permalink
Updating Ruby versions on Travis CI (#30)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
aried3r authored and simonc committed Jan 7, 2020
1 parent 26e0cb9 commit d8e61ab
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 12 deletions.
12 changes: 5 additions & 7 deletions .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
8 changes: 8 additions & 0 deletions lib/memfs.rb
Expand Up @@ -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'
Expand Down
6 changes: 6 additions & 0 deletions lib/memfs/dir.rb
Expand Up @@ -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?

Expand Down
10 changes: 8 additions & 2 deletions spec/fileutils_spec.rb
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions spec/memfs/dir_spec.rb
Expand Up @@ -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) }

Expand Down
13 changes: 10 additions & 3 deletions spec/memfs/file_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit d8e61ab

Please sign in to comment.