rails/rails — pull request #16728 by splattael (2014-08-28 07:23:58+00:00)
Title: Raise IPAddr::InvalidAddressError only if existent

`IPAddr::InvalidAddressError` is not defined in Ruby 1.9.3.

As JRuby 1.7.13 runs in 1.9 mode it fails to catch non-existent
`IPAddr::InvalidAddressError`.

It seems that MRI 1.9.3 evaluates the list of caught exceptions lazily
(`rescue ArgumentError, IPAddr::InvalidAddressError`) so tests pass
even `IPAddr::InvalidAddressError` is not defined because catching
`ArgumentError` is enough to move on.

Note: Rails 5.0 will drop support for 1.9.3 so this code has to be cleaned up
then.

## Demo

The following code demonstrates the failure:

```ruby
require 'ipaddr'

p :"IPAddr::InvalidAddressError" => defined? IPAddr::InvalidAddressError

begin
IPAddr.new("foo")
rescue ArgumentError, IPAddr::InvalidAddressError => e
p :error => e
end
```

### With MRI 2.1.2

```
{:"IPAddr::InvalidAddressError"=>"constant"}
{:error=>#}
```

### With MRI 1.9.3

```
{:"IPAddr::InvalidAddressError"=>nil}
{:error=>#}
```

### With JRuby in 1.9 mode

```
{:"IPAddr::InvalidAddressError"=>nil}
NameError: uninitialized constant IPAddr::InvalidAddressError
```