File tree Expand file tree Collapse file tree 3 files changed +13
-2
lines changed
Expand file tree Collapse file tree 3 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -67,9 +67,13 @@ def exception?(name)
6767
6868 def class_or_module ( c )
6969 const = Object . const_get ( c , false )
70+ return nil unless Module === const
71+
7072 filtered = @filter && EXCLUDED . include? ( const . name )
71- return const if Module === const and !filtered
72- rescue NameError
73+ return const unless filtered
74+ rescue NameError , RuntimeError
75+ # Either the constant doesn't exist or it is
76+ # explicitly raising an error, like `SortedSet`.
7377 end
7478
7579 def namespace ( mod , const )
Original file line number Diff line number Diff line change 1+ raise "This is a BAD file"
Original file line number Diff line number Diff line change @@ -21,6 +21,8 @@ class Fixnum
2121 def f ; end
2222 end
2323
24+ autoload :BadFile , "#{ __dir__ } /fixtures/this_file_raises.rb"
25+
2426 def self . n ; end
2527 def n ; end
2628end
@@ -84,6 +86,10 @@ def n; end
8486 expect ( @map . class_or_module ( "Hell" ) ) . to eq ( nil )
8587 expect ( @map . class_or_module ( "Bush::Brain" ) ) . to eq ( nil )
8688 end
89+
90+ it "returns nil if accessing the constant raises RuntimeError" do
91+ expect ( @map . class_or_module ( "NameMapSpecs::BadFile" ) ) . to eq ( nil )
92+ end
8793end
8894
8995RSpec . describe NameMap , "#dir_name" do
You can’t perform that action at this time.
0 commit comments