Changeset 4681
- Timestamp:
- 08/05/06 22:52:15 (2 years ago)
- Files:
-
- trunk/activesupport/CHANGELOG (modified) (1 diff)
- trunk/activesupport/lib/active_support/core_ext/name_error.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/dependencies.rb (modified) (3 diffs)
- trunk/activesupport/test/core_ext/name_error_test.rb (modified) (1 diff)
- trunk/activesupport/test/dependencies_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activesupport/CHANGELOG
r4679 r4681 1 1 *SVN* 2 3 * Raise fully qualified names upon name errors. #5533 [lars@pinds.com, Nicholas Seckar] 2 4 3 5 * Add extention to obtain the missing constant from NameError instances. [Nicholas Seckar] trunk/activesupport/lib/active_support/core_ext/name_error.rb
r4679 r4681 10 10 # Was this exception raised because the given name was missing? 11 11 def missing_name?(name) 12 missing_name == name.to_s 12 if name.is_a? Symbol 13 last_name = (missing_name || '').split('::').last 14 last_name == name.to_s 15 else 16 missing_name == name.to_s 17 end 13 18 end 14 19 trunk/activesupport/lib/active_support/dependencies.rb
r4604 r4681 70 70 end 71 71 72 # Return the a constant path for the provided parent and constant name 73 def constant_path_for(mod, name) 74 ([Object, Kernel].include? mod) ? name.to_s : "#{mod}::#{name}" 75 end 76 72 77 class LoadingModule 73 78 # Old style environment.rb referenced this method directly. Please note, it doesn't … … 121 126 end 122 127 123 raise NameError.new("uninitialized constant #{class_id}").copy_blame!(e) 128 qualified_name = Dependencies.constant_path_for self, class_id 129 raise NameError.new("uninitialized constant #{qualified_name}").copy_blame!(e) 124 130 end 125 131 end … … 131 137 super 132 138 else 133 parent.send :const_missing, class_id 139 begin 140 parent.send :const_missing, class_id 141 rescue NameError => e 142 # Make sure that the name we are missing is the one that caused the error 143 parent_qualified_name = Dependencies.constant_path_for parent, class_id 144 raise unless e.missing_name? parent_qualified_name 145 qualified_name = Dependencies.constant_path_for self, class_id 146 raise NameError.new("uninitialized constant #{qualified_name}").copy_blame!(e) 147 end 134 148 end 135 149 end trunk/activesupport/test/core_ext/name_error_test.rb
r4679 r4681 9 9 flunk "?!?!" 10 10 rescue NameError => exc 11 assert_equal " SomeNameThatNobodyWillUse____Really", exc.missing_name11 assert_equal "NameErrorTest::SomeNameThatNobodyWillUse____Really", exc.missing_name 12 12 assert exc.missing_name?(:SomeNameThatNobodyWillUse____Really) 13 assert exc.missing_name?(" SomeNameThatNobodyWillUse____Really")13 assert exc.missing_name?("NameErrorTest::SomeNameThatNobodyWillUse____Really") 14 14 end 15 15 end trunk/activesupport/test/dependencies_test.rb
r4595 r4681 156 156 end 157 157 end 158 159 def test_non_existing_const_raises_name_error_with_fully_qualified_name 160 with_loading 'autoloading_fixtures' do 161 begin 162 A::DoesNotExist 163 flunk "No raise!!" 164 rescue NameError => e 165 assert_equal "uninitialized constant A::DoesNotExist", e.message 166 end 167 begin 168 A::B::DoesNotExist 169 flunk "No raise!!" 170 rescue NameError => e 171 assert_equal "uninitialized constant A::B::DoesNotExist", e.message 172 end 173 end 174 end 175 176 def test_smart_name_error_strings 177 begin 178 Object.module_eval "ImaginaryObject" 179 flunk "No raise!!" 180 rescue NameError => e 181 assert e.message.include?("uninitialized constant ImaginaryObject") 182 end 183 end 184 158 185 end