Commit Graph

121 Commits

Author SHA1 Message Date
Josef Stribny 097ac2045a Do not depend on Rails git repository layout in ActiveSupport tests 2015-04-02 17:09:24 +02:00
claudiob 36effd916c Remove LoadError#path hack for Ruby 1.9
Now that Rails requires Ruby >= 2.0 there is need to skip the
`test_depend_on_path` test.
2015-01-04 15:54:21 -03:00
Rafael Mendonça França 48deeab90a Merge pull request #8740 from amatsuda/missing_source_file
replace use of MissingSourceFile with LoadError

Conflicts:
	activesupport/test/core_ext/load_error_test.rb
2015-01-02 19:19:59 -03:00
Xavier Noria 0ed6ebcf90 dependencies.rb: keep the decorated #load and #require private [closes #17553] 2014-11-10 14:29:29 -08:00
Yves Senn 00ae750b23 Merge pull request #15956 from zuhao/refactor_activesupport_dependencies_test
Cleanup loaded features and constants after dependency tests.
2014-11-05 15:40:37 +01:00
Xavier Noria ae07806858 fixes circularity check in dependencies
The check for circular loading should depend on a stack of files being
loaded at the moment, rather than the collection of loaded files.

This showed up indirectly in #16468, where a misspelled helper would
incorrectly result in a circularity error message.

References #16468
2014-10-25 14:06:33 +02:00
Guo Xiang Tan 6e0f273dfd Use `safe_constantize`.
Fixes https://github.com/rails/rails/issues/9933.
2014-09-02 00:41:00 +08:00
Akira Matsuda 6e440a0147 Reset ActiveSupport::Dependencies.mechanism to make tests order independent 2014-08-13 21:25:11 +09:00
Akira Matsuda fe873dfae2 Duplicated method in the test helper 2014-08-13 21:25:11 +09:00
Zuhao Wan d75f4dcb0e Cleanup loaded features and constants after dependency tests. 2014-06-28 17:57:27 +08:00
Yuki Nishijima 98f0cab396 Fix a bug where NameError#name returns a qualified name in string
Ruby's original behaviour is that :

  * It only returns a const name, not a qualified aname
  * It returns a symbol, not a string
2014-06-24 10:13:17 -07:00
Arthur Neves bd3fde0931
Add regression test for NameError#name 2014-06-20 09:55:41 -04:00
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
Akira Matsuda 370bfda55f replace use of MissingSourceFile with LoadError 2013-01-04 16:46:22 +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 a10606c490 (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