Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add File.executable? #179

Merged
merged 1 commit into from

2 participants

@xaviershay

No description provided.

@smtlaissezfaire smtlaissezfaire merged commit be3153a into defunkt:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 10, 2013
  1. @xaviershay

    Add File.executable?

    xaviershay authored
This page is out of date. Refresh to see the latest.
Showing with 15 additions and 0 deletions.
  1. +6 −0 lib/fakefs/file.rb
  2. +9 −0 test/fakefs_test.rb
View
6 lib/fakefs/file.rb
@@ -236,6 +236,12 @@ def self.chmod(mode_int, filename)
FileSystem.find(filename).mode = 0100000 + mode_int
end
+ # Not exactly right, returns true if the file is chmod +x for owner. In the
+ # context of when you would use fakefs, this is usually what you want.
+ def self.executable?(filename)
+ (FileSystem.find(filename).mode - 0100000) & 0100 != 0
+ end
+
def self.chown(owner_int, group_int, filename)
file = FileSystem.find(filename)
if owner_int && owner_int != -1
View
9 test/fakefs_test.rb
@@ -785,6 +785,7 @@ def test_can_chmod_files
assert_equal [good], FileUtils.chmod(0600, good, :verbose => true)
assert_equal File.stat(good).mode, 0100600
+ assert_equal File.executable?(good), false
assert_raises(Errno::ENOENT) do
FileUtils.chmod(0600, bad)
end
@@ -800,6 +801,14 @@ def test_can_chmod_files
assert_raises(Errno::ENOENT) do
FileUtils.chmod(0644, bad)
end
+
+ assert_equal [good], FileUtils.chmod(0744, [good])
+ assert_equal File.executable?(good), true
+
+ # This behaviour is unimplemented, the spec below is only to show that it
+ # is a deliberate YAGNI omission.
+ assert_equal [good], FileUtils.chmod(0477, [good])
+ assert_equal File.executable?(good), false
end
def test_can_chmod_R_files
Something went wrong with that request. Please try again.