Skip to content
Permalink
Browse files
fix File.readable? when native is disabled
this readable? method now follows the same pattern as writable?, file?,
directory? and exists? and uses the respective FileResource directly.

fixes #2040 and #1983

Sponsored by Lookout Inc.
  • Loading branch information
mkristian committed Dec 2, 2014
1 parent 17c67a6 commit 8a5ea5c80256c6c437b08a0597e6d6f2311a1b34
Showing with 9 additions and 2 deletions.
  1. +1 −2 core/src/main/java/org/jruby/RubyFileTest.java
  2. +8 −0 test/test_file.rb
@@ -197,8 +197,7 @@ public static IRubyObject readable_p(ThreadContext context, IRubyObject recv, IR
filename = get_path(context, filename);
}

FileStat stat = fileResource(filename).stat();
return runtime.newBoolean(stat != null && stat.isReadable());
return runtime.newBoolean(fileResource(filename).canRead());
}

// Not exposed by filetest, but so similiar in nature that it is stored here
@@ -484,6 +484,14 @@ def test_file_query # - file?
assert(result == 'falsefalsetrue')
end

def test_readable_query # - readable?
assert(File.readable?('test/test_file.rb'))
assert(File.readable?('test'))
assert(! File.readable?('test_not'))
result = jruby("-e 'print File.readable?(\"test_not\");print File.readable?(\"test\");print File.readable?(\"test/test_file.rb\")'", 'jruby.native.enabled' => 'false' )
assert(result == 'falsetruetrue')
end

def test_file_exist_query
assert(File.exist?('test'))
assert(! File.exist?('test_not'))

0 comments on commit 8a5ea5c

Please sign in to comment.