Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 43 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,56 @@ on:
pull_request:
branches:
- main
# Run workflow manually
workflow_dispatch:

jobs:
rubocop:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v5

- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "4.0"

- name: Bundler
run: bundle install

- name: Rubocop
run: bin/rubocop

specs:
name: Rubocop & Rspec
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
ruby-version: ['3.4', '3.3', '3.2', '3.1', '3.0', '2.7']
ruby:
- "4.0"
- "3.4"
- "3.3"
- "3.2"
- "3.1"
- "3.0"
- "2.7"

env:
# Check for frozen strings
RUBYOPT: "--enable=frozen-string-literal --debug=frozen-string-literal"

steps:
- uses: actions/checkout@v3
- name: Set up Ruby ${{matrix.ruby-version}}
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{matrix.ruby-version}}
bundler-cache: true
- name: Install dependencies
run: bundle install --quiet
- name: Rubocop
run: bundle exec rubocop -D
- name: Rspec
run: bundle exec rspec
- name: Checkout
uses: actions/checkout@v5

- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true

- name: RSpec
run: bin/rspec
2 changes: 1 addition & 1 deletion .rspec
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
--color
--require spec_helper
--warnings
9 changes: 8 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
---
plugins:
- rubocop-performance
- rubocop-rake
- rubocop-rspec

AllCops:
Exclude:
- bin/*
- memfs.gemspec
- spec/**/*
- vendor/bundle/**/*
Expand Down Expand Up @@ -44,7 +51,7 @@ Metrics/ClassLength:
Metrics/MethodLength:
Max: 10

Naming/PredicateName:
Naming/PredicatePrefix:
ForbiddenPrefixes:
- is_

Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## HEAD

* ADD: Support for Ruby 3.x
* ADD: Support for Ruby 3.x and 4.x
* ADD: `Dir.empty?`
* ADD: `IO#fileno` and `Dir#fileno` raise `NotImplementedError`
* ADD: `File.birthtime` and `File#birthtime`
Expand Down
16 changes: 16 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,19 @@ source 'https://rubygems.org'

# Specify your gem's dependencies in memfs.gemspec
gemspec

# Dev libs
gem 'coveralls', '~> 0.6'
gem 'listen', '~> 3.1'
gem 'rake', '~> 13.0'
gem 'rb-fchange', '~> 0.0'
gem 'rb-fsevent', '~> 0.9'
gem 'rb-inotify', '~> 0.8'
gem 'rspec', '~> 3.0'

# Dev tools / linter
gem 'guard-rspec', require: false
gem 'rubocop', require: false
gem 'rubocop-performance', require: false
gem 'rubocop-rake', require: false
gem 'rubocop-rspec', require: false
16 changes: 16 additions & 0 deletions bin/_guard-core
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application '_guard-core' is installed as part of a gem, and
# this file is here to facilitate running it.
#

ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)

require "rubygems"
require "bundler/setup"

load Gem.bin_path("guard", "_guard-core")
16 changes: 16 additions & 0 deletions bin/guard
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'guard' is installed as part of a gem, and
# this file is here to facilitate running it.
#

ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)

require "rubygems"
require "bundler/setup"

load Gem.bin_path("guard", "guard")
16 changes: 16 additions & 0 deletions bin/rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'rake' is installed as part of a gem, and
# this file is here to facilitate running it.
#

ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)

require "rubygems"
require "bundler/setup"

load Gem.bin_path("rake", "rake")
16 changes: 16 additions & 0 deletions bin/rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'rspec' is installed as part of a gem, and
# this file is here to facilitate running it.
#

ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)

require "rubygems"
require "bundler/setup"

load Gem.bin_path("rspec-core", "rspec")
16 changes: 16 additions & 0 deletions bin/rubocop
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'rubocop' is installed as part of a gem, and
# this file is here to facilitate running it.
#

ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)

require "rubygems"
require "bundler/setup"

load Gem.bin_path("rubocop", "rubocop")
60 changes: 58 additions & 2 deletions lib/memfs/dir.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ def self.getwd
end
class << self; alias pwd getwd; end

def self.glob(patterns, flags = 0, &block)
def self.glob(patterns, flags = 0, base: nil, sort: true, **opts, &block)
# Handle keyword argument for flags
flags = opts[:flags] if opts.key?(:flags)

patterns = [*patterns].map(&:to_s)
list = fs.paths.select do |path|
patterns.any? do |pattern|
Expand All @@ -68,8 +71,9 @@ def self.glob(patterns, flags = 0, &block)
end
# FIXME: ugly special case for /* and /
list.delete('/') if patterns.first == '/*'

return list unless block_given?
list.each { |path| block.call(path) }
list.each(&block)
nil
end

Expand Down Expand Up @@ -101,6 +105,58 @@ def self.tmpdir
'/tmp'
end

def self.mktmpdir(prefix_suffix = nil, tmpdir = nil, **options)
tmpdir ||= self.tmpdir

case prefix_suffix
when nil
prefix = 'd'
suffix = ''
when String
prefix = prefix_suffix
suffix = ''
when Array
prefix = prefix_suffix[0] || 'd'
suffix = prefix_suffix[1] || ''
else
raise ArgumentError, "unexpected prefix_suffix: #{prefix_suffix.inspect}"
end

max_try = options.fetch(:max_try, 10000)
path = nil

max_try.times do
timestamp = Time.now.strftime('%Y%m%d')
random = sprintf('%d-%d', $$, rand(0x100000000))
path = File.join(tmpdir, "#{prefix}#{timestamp}-#{random}-0#{suffix}")

begin
mkdir(path, 0o700)
break
rescue Errno::EEXIST
path = nil
next
end
end

raise "cannot generate temporary directory name" if path.nil?

if block_given?
begin
result = yield path
ensure
begin
rmdir(path) if exists?(path)
rescue
# Ignore cleanup errors
end
end
result
else
path
end
end

class << self
alias delete rmdir
alias unlink rmdir
Expand Down
6 changes: 3 additions & 3 deletions lib/memfs/io.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,22 +115,22 @@ def external_encoding
def each(sep = $/, &block)
return to_enum(__callee__, sep) unless block_given?
fail IOError, 'not opened for reading' unless readable?
content.each_line(sep) { |line| block.call(line) }
content.each_line(sep, &block)
self
end

def each_byte(&block)
return to_enum(__callee__) unless block_given?
fail IOError, 'not opened for reading' unless readable?
content.each_byte { |byte| block.call(byte) }
content.each_byte(&block)
self
end
alias bytes each_byte

def each_char(&block)
return to_enum(__callee__) unless block_given?
fail IOError, 'not opened for reading' unless readable?
content.each_char { |char| block.call(char) }
content.each_char(&block)
self
end
alias chars each_char
Expand Down
18 changes: 0 additions & 18 deletions memfs.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,6 @@ Gem::Specification.new do |gem|
'for tests. Strongly inspired by FakeFS.'
gem.summary = "memfs-#{MemFs::VERSION}"
gem.homepage = 'http://github.com/simonc/memfs'

gem.license = 'MIT'

gem.files = `git ls-files`.split($/)
gem.executables = gem.files.grep(/^bin\//).map { |f| File.basename(f) }
gem.test_files = gem.files.grep(/^(test|spec|features)\//)
gem.require_paths = ['lib']

gem.add_development_dependency 'coveralls', '~> 0.6'
gem.add_development_dependency 'rake', '~> 12.0'
gem.add_development_dependency 'rspec', '~> 3.0'
gem.add_development_dependency 'guard', '~> 2.6'
gem.add_development_dependency 'guard-rspec', '~> 4.3'
gem.add_development_dependency 'rb-inotify', '~> 0.8'
gem.add_development_dependency 'rb-fsevent', '~> 0.9'
gem.add_development_dependency 'rb-fchange', '~> 0.0'
gem.add_development_dependency 'rubocop', '~> 1.44'

listen_version = RUBY_VERSION >= '2.2.3' ? '~> 3.1' : '~> 3.0.7'
gem.add_development_dependency 'listen', listen_version
end
Loading