diff options
| author | Charles Oliver Nutter <headius@headius.com> | 2025-11-18 19:38:18 -0600 |
|---|---|---|
| committer | Benoit Daloze <eregontp@gmail.com> | 2025-11-19 12:36:40 +0100 |
| commit | bbb4c7b88bf4fca08487d6b115b1031f56ac9cf6 (patch) | |
| tree | 23c9c56ccbcc8a266eb7da176aeaa9eca67a52bd | |
| parent | 169d6c7cadce7a27e62d9943559b9f712ea231f8 (diff) | |
Update to ruby/mspec@bd8efcf
| -rw-r--r-- | spec/mspec/lib/mspec/utils/name_map.rb | 13 | ||||
| -rw-r--r-- | spec/mspec/spec/utils/fixtures/this_file_raises.rb | 1 | ||||
| -rw-r--r-- | spec/mspec/spec/utils/fixtures/this_file_raises2.rb | 1 | ||||
| -rw-r--r-- | spec/mspec/spec/utils/name_map_spec.rb | 12 |
4 files changed, 24 insertions, 3 deletions
diff --git a/spec/mspec/lib/mspec/utils/name_map.rb b/spec/mspec/lib/mspec/utils/name_map.rb index bf70e651a2..9b04112e2e 100644 --- a/spec/mspec/lib/mspec/utils/name_map.rb +++ b/spec/mspec/lib/mspec/utils/name_map.rb @@ -66,10 +66,17 @@ class NameMap end def class_or_module(c) - const = Object.const_get(c, false) + begin + const = Object.const_get(c, false) + rescue NameError, RuntimeError + # Either the constant doesn't exist or it is + # explicitly raising an error, like `SortedSet`. + return nil + end + return nil unless Module === const + filtered = @filter && EXCLUDED.include?(const.name) - return const if Module === const and !filtered - rescue NameError + return const unless filtered end def namespace(mod, const) diff --git a/spec/mspec/spec/utils/fixtures/this_file_raises.rb b/spec/mspec/spec/utils/fixtures/this_file_raises.rb new file mode 100644 index 0000000000..8e37a587bf --- /dev/null +++ b/spec/mspec/spec/utils/fixtures/this_file_raises.rb @@ -0,0 +1 @@ +raise "This is a BAD file" diff --git a/spec/mspec/spec/utils/fixtures/this_file_raises2.rb b/spec/mspec/spec/utils/fixtures/this_file_raises2.rb new file mode 100644 index 0000000000..8efc10199a --- /dev/null +++ b/spec/mspec/spec/utils/fixtures/this_file_raises2.rb @@ -0,0 +1 @@ +raise "This is a BAD file 2" diff --git a/spec/mspec/spec/utils/name_map_spec.rb b/spec/mspec/spec/utils/name_map_spec.rb index a18a481500..a42dc9ffec 100644 --- a/spec/mspec/spec/utils/name_map_spec.rb +++ b/spec/mspec/spec/utils/name_map_spec.rb @@ -21,6 +21,9 @@ module NameMapSpecs def f; end end + autoload :BadFile, "#{__dir__}/fixtures/this_file_raises.rb" + autoload :BadFile2, "#{__dir__}/fixtures/this_file_raises2.rb" + def self.n; end def n; end end @@ -84,6 +87,15 @@ RSpec.describe NameMap, "#class_or_module" do expect(@map.class_or_module("Hell")).to eq(nil) expect(@map.class_or_module("Bush::Brain")).to eq(nil) end + + it "returns nil if accessing the constant raises RuntimeError" do + expect { NameMapSpecs::BadFile }.to raise_error(RuntimeError) + expect(@map.class_or_module("NameMapSpecs::BadFile")).to eq(nil) + end + + it "returns nil if accessing the constant raises RuntimeError when not triggering the autoload before" do + expect(@map.class_or_module("NameMapSpecs::BadFile2")).to eq(nil) + end end RSpec.describe NameMap, "#dir_name" do |
