diff options
author | Robin Dupret <robin.dupret@gmail.com> | 2014-07-26 20:10:43 +0200 |
---|---|---|
committer | Robin Dupret <robin.dupret@gmail.com> | 2014-08-08 15:20:21 +0200 |
commit | 7a41295734e2a2332dc09db08f08eda36f927ca3 (patch) | |
tree | ee795d6510341431a07b975f8c602e7a936b6f2e /actionview/test/template/text_test.rb | |
parent | 89ad1d85aa0462abd04bd0cf97a6daa0149f303e (diff) | |
download | rails-7a41295734e2a2332dc09db08f08eda36f927ca3.tar.gz rails-7a41295734e2a2332dc09db08f08eda36f927ca3.tar.bz2 rails-7a41295734e2a2332dc09db08f08eda36f927ca3.zip |
Avoid relying on error messages when rescuing
When we are rescuing from an error, it's a brittle approach to do checks
with regular expressions on the raised message because it may change in
in the future and error messages are different across implementations.
The NameError API could be improved at the MRI level but for now we need
to rely on its #name. A #== check will only pass for top level constants
or only when the last constant of the path is missing so we need to rely
on #include? instead. For instance:
begin
Namespace::Foo
rescue NameError => e
e.name # => :Namespace
end
However, if the name-space already exists, only the name of the first
missing constant in the path is returned (e.g. for Math::PHI, the name
would be :PHI). JRuby will return a fully qualified name (:"Math::PHI").
We need to keep the == check for 1.9 compatibility since const_get will
raise a NameError with a name attribute set to the given string if it's
one of "::" or "".
See http://git.io/jnSN7g for further information.
Diffstat (limited to 'actionview/test/template/text_test.rb')
0 files changed, 0 insertions, 0 deletions