Skip to content

Commit

Permalink
Add spec that Module#to_s does not call #inspect if it's a singleton …
Browse files Browse the repository at this point in the history
…class
  • Loading branch information
eregon committed Dec 28, 2020
1 parent 4ee69b8 commit caf668f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions core/module/to_s_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,17 @@ module ModuleSpecs::RefinementInspect
ModuleSpecs::RefinementInspect::R.name.should == 'ModuleSpecs::RefinementInspect::R'
ModuleSpecs::RefinementInspect::R.to_s.should == '#<refinement:String@ModuleSpecs::RefinementInspect>'
end

it 'does not call #inspect or #to_s for singleton classes' do
klass = Class.new
obj = klass.new
def obj.to_s
"to_s"
end
def obj.inspect
"inspect"
end
sclass = obj.singleton_class
sclass.to_s.should =~ /\A#<Class:#<#{Regexp.escape klass.to_s}:0x\h+>>\z/
end
end

0 comments on commit caf668f

Please sign in to comment.