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

Fix Dir.entries on ruby-2.1.0-preview2 #209

Merged
merged 1 commit into from
Dec 23, 2013

Conversation

benjaminoakes
Copy link
Contributor

Ruby 2.1.0's Dir.entries method now allows an "encoding" option. Without this change, ArgumentError: wrong number of arguments (2 for 1) is raised.

See also http://ruby-doc.org/core-2.1.0/Dir.html

I found this while working on Ruby 2.1.0 compatibility for Maid. As a part of debugging Maid's specs, I extracted a minimal spec that demonstrates the problem. It's currently in spec/fakefs/fakefs_bug_ruby_2.1.0-preview2.rb.

Thanks for maintaining FakeFS. It makes Maid's specs much easier to write!

Ben

Ruby 2.1's Dir.entries method now allows an "encoding" option.  Without this change, an ArgumentError is raised.

See also http://ruby-doc.org/core-2.1.0/Dir.html
@@ -80,7 +80,7 @@ def self.delete(string)
FileSystem.delete(string)
end

def self.entries(dirname)
def self.entries(dirname, opts = {})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the docs the second argument here is an encoding, which I take to mean a string. This should probably be called encoding and default to nil.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could see changing the name from opts. However, I don't think it can be nil -- it's expecting a hash, according to the docs (encoding: enc). Perhaps this?

def self.entries(dirname, opts = { :encoding => nil })

Or if you're okay with new syntax:

def self.entries(dirname, encoding: nil)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I was misreading the docs. I believe this is fine as-is.

@eventualbuddha
Copy link
Contributor

Could you give a little more detail how Find.find interacts with Dir.entries to cause the error you're seeing in Ruby 2.1?

@benjaminoakes
Copy link
Contributor Author

Unfortunately, I don't know all the mechanics of how Find.find interacts with Dir.entries, just that fakefs ends up calling Dir.entries when Find.find is called. For more details, it might be helpful to see this blog entry that I wrote.

The purpose of this pull request is to demonstrate that Dir.entries has changed in Ruby 2.1 and that a second argument needs to be handled in fakefs. The test case in spec/fakefs/fakefs_bug_ruby_2.1.0-preview2.rb is one example. It would seem that other calls that involve Dir.entries would break on Ruby 2.1 as well.

I hope this helps clarify the issue! Really, it's just a one line change to be compatible with Ruby 2.1.

@eventualbuddha eventualbuddha merged commit 8276d8e into fakefs:master Dec 23, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants