Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Ruby versions on Travis CI #30

Merged
merged 7 commits into from
Jan 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 5 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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?
simonc marked this conversation as resolved.
Show resolved Hide resolved
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