Commit Graph

108 Commits

Author SHA1 Message Date
Noah Lindner
4fa8c8b52f Fixed an issue where reloading of removed dependencies would cause an unexpected circular dependency error 2014-02-08 15:59:08 -08:00
Carlos Antonio da Silva
c5b76b5362 Prefer assert_raise instead of flunk + rescue to test for exceptions
Change most tests to make use of assert_raise returning the raised
exception rather than relying on a combination of flunk + rescue to
check for exception types/messages.
2013-12-19 09:20:51 -02:00
Carlos Antonio da Silva
d799b9c1cf Fix asserting the correct exception message in dependencies test
In Minitest, the second argument of assert_raise(s) accepts a string as
the message that should be shown in case of a failure in the assertion
(eg nothing was raised when it should), and not the exception message to
be matched.

To do that we need to save the exception returned from assert_raise(s)
into a local variable and check for the exception message using it.
2013-12-19 08:47:09 -02:00
Xavier Noria
01c9782fa2 better error message for constants autoloaded from anonymous modules [fixes #13204]
load_missing_constant is a private method that basically plays the role of const_missing.
This method has an error condition that is surprising: it raises if the class or module
already has the missing constant. How is it possible that if the class of module has
the constant Ruby has called const_missing in the first place?

The answer is that the from_mod argument is self except for anonymous modules, because
const_missing passes down Object in such case (see the comment in the source code of the
patch for the rationale).

But then, it is better to pass down Object *if Object is also missing the constant* and
otherwise err with an informative message right away.
2013-12-06 19:18:10 +01:00
Xavier Noria
2254615bff Merge pull request #12412 from bf4/allow_pathname_for_require_dependency
Allow Pathname for require dependency
2013-09-30 23:22:11 -07:00
Benjamin Fleischer
0b0beb71d6 require_dependency should allow Pathname-like objects, not just String 2013-09-30 19:57:03 -05:00
Simon Coffey
b4a9668626 Ensure all-caps nested consts marked as autoloaded
Previously, an autoloaded constant `HTML::SomeClass` would not be marked
as autoloaded by AS::Dependencies. This is because the
`#loadable_constants_for_path` method uses `String#camelize` on the
inferred file path, which in turn means that, unless otherwise directed,
AS::Dependencies watches for loaded constants in the `Html` namespace.

By passing the original qualified constant name to `#load_or_require`,
this inference step is avoided, and the new constant is picked up in the
correct namespace.
2013-08-27 08:20:33 +01:00
Andrew Kreiling
a548792aa0 Don't blindly call blame_file! on exceptions in ActiveSupport::Dependencies::Loadable
It is possible under some environments to receive an Exception that is
not extended with Blamable (e.g. JRuby).
ActiveSupport::Dependencies::Loadable#load_dependency blindly call
blame_file! on the exception which throws it's own NoMethodError
exception and hides the original Exception.

This commit fixes #9521
2013-06-09 18:20:10 -04:00
Vipul A M
6944dfb5d0 remove redundant var 2013-05-09 18:23:27 +05:30
Carlos Antonio da Silva
466ff9310a Merge pull request #9681 from vipulnsward/fix_typo_in_module_name
Fix typo in DependenciesTestHelpers module name
2013-03-12 03:55:30 -07:00
Vipul A M
8778e1c4af Fix typo in DependenciesTestHelpers module name 2013-03-12 10:33:32 +05:30
Vipul A M
647a9abb02 Cleanup tests for unused variables 2013-03-11 16:03:10 +05:30
Akira Matsuda
70ae89c321 Remove unnecessary begin..rescue..end, use only rescue 2013-01-06 15:41:14 +09:00
Xavier Noria
26c024e959 silences "possibly useless use of :: in void context" warnings
The AS utility silence_warnings does not really silence this
one, because it is issued at parse-time. It seemed to in
some places because the constant was the only expression in
the block and therefore it was its return value, that could
potentially be used by silence_warnings are return value of
the yield call.

To bypass the warning we assign to a variable. The chosen
variable is "_" because it is special-cased in parse.c not
to issue an "assigned but unused variable" warning in turn.
2012-12-24 21:16:16 +01:00
kennyj
180e2e5e9e silence warning: possibly useless use of a constant in void context 2012-12-06 01:10:03 +09:00
Uriel Katz
9ee0ffb360 Patched Marshal#load to work with constant autoloading (active_support/dependecies.rb) (issue #8167) 2012-12-01 14:00:16 +02:00
Xavier Noria
46ebce6b49 prevent Dependencies#remove_const from autoloading parents [fixes #8301] 2012-11-28 00:13:14 +01:00
Xavier Noria
a8c3ea90f1 let remove_constant still delete Kernel#autoload constants [rounds #8213]
The method #remove_const does not load the file, so we
can still remove the constant.
2012-11-15 11:10:03 +01:00
Xavier Noria
bff4d8d165 dependencies no longer trigger Kernel#autoload in remove_const [fixes #8213] 2012-11-15 04:36:36 +01:00
Carlos Antonio da Silva
d46f9e3731 Fix some assert_raise calls containing messages in Active Support 2012-10-28 17:54:24 -02:00
Xavier Noria
b33700f558 detect circular constant autoloading
Nowadays circular autoloads do not work, but the user gets a NameError
that says some constant is undefined. That's puzzling, because he is
normally trying to autoload a constant he knows can be autoloaded.
With this check we can give a better error message.
2012-08-28 20:34:39 +02:00
Francesco Rodriguez
cc14a3b2c1 Fix ActiveSupport tests that depend on run order 2012-08-23 16:00:58 -05:00
Aaron Patterson
56a1bb2f10 raise the same exception in order to keep path info
Ruby 2.0.0 implements LoadError#path, but newly raised load errors will
not contain the path information.  Replace the error message, copy
blame, and rereaise the same exception object
2012-06-12 16:19:51 -07:00
Xavier Noria
d3a99c32d1 removes the obsolete require_association method from dependencies
This is an obsolete method from the very early days,
apparently it was used circa 2004 because STI support
was not smart enough. This method is not public
interface, and we are heading a major version, so
removal seems right.
2012-06-10 00:38:40 +02:00
Aaron Patterson
b8d8c50785 use AS::TestCase as the base class 2012-01-05 17:12:46 -08:00
Sam Umbach
cfc467f73e Simplify load and require tests
- These tests don't use autoloading so there's no need to add anything to autoload_paths
2011-12-03 13:11:02 -05:00
Sam Umbach
2a9f063082 Test that require and load raise LoadError if file not found 2011-12-03 13:08:18 -05:00
Sam Umbach
0a485309a0 Test return value of ActiveSupport::Dependencies::Loadable#load 2011-12-03 12:58:41 -05:00
Sam Umbach
93580f4936 Test return value of ActiveSupport::Dependencies::Loadable#require
- Add tests to protect from regressions in require's return value behavior
- See a10606c490471d8e1483acb3b31d7f2d51e9ebbe (require needs to return true or false) for the original bug fix
2011-12-03 11:52:25 -05:00
Jonathan del Strother
e0714ee005 Fix autoload_once_paths when using Pathnames & ruby 1.9
Under ruby 1.9.2 -
  "/var/log".starts_with?(Pathname.new("/var"))  # => false

so setting config.autoload_once_paths with Pathnames would not work
2011-08-24 18:14:25 +01:00
Arun Agrawal
ec7457ed2a Removing extra requires from the test. Already loaded in abstract_unit. 2011-07-31 23:36:21 +05:30
Andrew White
cf3364a03c Raise NameError instead of ArgumentError in ActiveSupport::Dependencies
ActiveSupport::Dependencies now raises NameError if it finds an existing
constant in load_missing_constant. This better reflects the nature of
the error which is usually caused by calling constantize on a nested constant.

Closes #1423
2011-06-01 01:16:20 +01:00
José Valim
a6e945554d Fix failing tests. 2011-05-22 13:21:47 +02:00
Aaron Patterson
69e348013b adding deprecation noticies to deprecated class cache methods 2011-03-02 09:31:40 -08:00
Aaron Patterson
66245441d4 adding backwards compat for class cache references. <3<3 2011-03-02 09:18:05 -08:00
Aaron Patterson
7b6bfe84f3 refactor Reference to a ClassCache object, fix lazy lookup in Middleware so that anonymous classes are supported 2011-03-01 17:20:35 -08:00
Andrew White
f1966337fa Add before_remove_const callback to ActiveSupport::Dependencies.remove_unloadable_constants!
Signed-off-by: Xavier Noria <fxn@hashref.com>
2010-09-01 22:32:41 +02:00
wycats
dbe08026e1 Sadly, this segv's in 1.8 :( 2010-08-17 16:51:35 -07:00
Santiago Pastorino
4ea1753fc2 This is for making sure const_missing is triggered without warnings 2010-07-26 12:51:52 -03:00
wycats
1b97701e51 Fix a bug where requires inside of autoloads were being added to the autoloaded_constants list, causing mayhem. [#5165 state:resolved] 2010-07-26 00:59:54 -07:00
Santiago Pastorino
e1d4e78b15 Removes unused vars
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-07-24 01:19:44 +02:00
Santiago Pastorino
80cf6559ed Makes restore previosly saved warnings_on_first_load value and avoid warning
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-07-24 01:19:43 +02:00
Xavier Noria
6f83a5036d renames load_(once_)paths to autoload_(once_)paths in dependencies and config 2010-06-24 00:17:28 +02:00
Jeremy Kemper
fd1a504136 ActiveSupport::Dependencies.constantize shortcut for caching named constant lookups 2010-06-05 22:05:58 -07:00
wycats
a6b3942843 Optimize LookupContext 2010-06-04 20:11:06 -07:00
Santiago Pastorino
aacf2581cd refactor evals and adds some __FILE__ and __LINE__
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-05-20 15:18:57 +02:00
Santiago Pastorino and Sebastian Martinez
e7276a9f09 Make dependencies_test pass running standalone [#4215 state:resolved]
Signed-off-by: wycats <wycats@gmail.com>
2010-03-18 17:50:28 -07:00
Yehuda Katz
4da45060a2 Simplify dependencies.rb some. Remove alias of Kernel::Foo to Object::Foo as it was not used and breaks Ruby semantics. 2010-02-14 10:48:06 -08:00
Yehuda Katz
77f630d317 Since require_dependency cannot be cleared, remove the dependencies 2010-02-10 15:06:42 -08:00
Xavier Noria
cf9a52a7b6 removes Module#as_load_path, which is no longer used 2010-02-07 23:06:15 +01:00