Skip to content

Commit

Permalink
fix File.readable? when native is disabled
Browse files Browse the repository at this point in the history
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 8a5ea5c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 1 addition & 2 deletions core/src/main/java/org/jruby/RubyFileTest.java
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions test/test_file.rb
Expand Up @@ -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'))
Expand Down

0 comments on commit 8a5ea5c

Please sign in to comment.