Skip to content

Commit

Permalink
adjust TypeError's conversion failed error message to match MRI closer
Browse files Browse the repository at this point in the history
kares committed Jul 15, 2017
1 parent 17d4f48 commit 80e9fbc
Showing 5 changed files with 35 additions and 6 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/util/TypeConverter.java
Original file line number Diff line number Diff line change
@@ -353,7 +353,7 @@ public static IRubyObject handleUncoercibleObject(boolean raise, IRubyObject obj
}

public static IRubyObject handleUncoercibleObject(Ruby runtime, IRubyObject obj, RubyClass target, boolean raise) {
if (raise) throw runtime.newTypeError("no implicit conversion of " + typeAsString(obj) + " into " + target);
if (raise) throw runtime.newTypeError("can't convert " + typeAsString(obj) + " into " + target);
return runtime.getNil();
}

10 changes: 10 additions & 0 deletions test/jruby/test_array.rb
Original file line number Diff line number Diff line change
@@ -62,4 +62,14 @@ def test_collect_concurrency
end
end

def test_pack_type_error_message
obj = Object.new
begin
[ obj ].pack('D')
fail 'expected to raise a TypeError'
rescue TypeError => e
assert_equal "can't convert Object into Float", e.message
end
end

end
18 changes: 14 additions & 4 deletions test/jruby/test_file.rb
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
require 'fileutils'
require 'tempfile'
require 'pathname'
require 'jruby'
require 'jruby' if defined? JRUBY_VERSION

class TestFile < Test::Unit::TestCase
include TestHelper
@@ -22,7 +22,7 @@ def teardown
end

def jruby_specific_test
flunk("JRuby specific test") unless defined?(JRUBY_VERSION)
skip("JRuby specific test") unless defined?(JRUBY_VERSION)
end

def test_file_separator_constants_defined
@@ -893,7 +893,7 @@ def test_file_open_utime

def test_file_utime_nil
filename = '__test__file'
File.open(filename, 'w') {|f| }
File.open(filename, 'w') { |f| assert f }
time = File.mtime(filename)
sleep 2
File.utime(nil, nil, filename)
@@ -902,6 +902,16 @@ def test_file_utime_nil
File.unlink(filename)
end

def test_utime_convert_time
filename = '__test__file'
File.open(filename, 'w') { |f| assert f }
begin
File.utime(0, Object.new, filename)
rescue TypeError => e
assert_match /can't convert Object into Time/i, e.message
end
end

def test_file_utime_bad_time_raises_typeerror
args = [ [], {}, '4000' ]
filename = '__test__file'
@@ -939,7 +949,7 @@ def test_file_stat # File::Stat tests
assert(stat2.readable?)
end

if WINDOWS && JRuby::runtime.posix.native?
if WINDOWS && defined?(JRuby) && JRuby::runtime.posix.native?
# JRUBY-2351
def test_not_implemented_methods_on_windows
# the goal here is to make sure that those "weird"
2 changes: 1 addition & 1 deletion test/jruby/test_helper.rb
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@ module TestHelper

IBM_JVM = RbConfig::CONFIG['host_vendor'] =~ /IBM Corporation/

JAVA_8 = ENV_JAVA['java.specification.version'] >= '1.8'
JAVA_8 = ENV_JAVA['java.specification.version'] >= '1.8' rescue nil

def q
WINDOWS ? '"' : '\''
9 changes: 9 additions & 0 deletions test/jruby/test_kernel.rb
Original file line number Diff line number Diff line change
@@ -319,6 +319,15 @@ def test_raise_in_debug_mode
# select
# set_trace_func

def test_select_convert_timeout_error_msg
timeout = Object.new
begin
Kernel.select [$stdin], nil, nil, timeout
rescue TypeError => ex
assert ex.message.start_with? "can't convert Object into"
end
end


def test_sleep
assert_raises(ArgumentError) { sleep(-10) }

0 comments on commit 80e9fbc

Please sign in to comment.