diff --git a/core/module/refinements_spec.rb b/core/module/refinements_spec.rb new file mode 100644 index 000000000..5648fcbd6 --- /dev/null +++ b/core/module/refinements_spec.rb @@ -0,0 +1,45 @@ +require_relative '../../spec_helper' + +describe "Module#refinements" do + ruby_version_is "3.2" do + it "returns refinements defined in a module" do + ScratchPad.record [] + + m = Module.new do + refine String do + ScratchPad << self + end + + refine Array do + ScratchPad << self + end + end + + m.refinements.sort_by(&:object_id).should == ScratchPad.recorded.sort_by(&:object_id) + end + + it "does not return refinements defined in the included module" do + ScratchPad.record [] + + m1 = Module.new do + refine Integer do + nil + end + end + + m2 = Module.new do + include m1 + + refine String do + ScratchPad << self + end + end + + m2.refinements.should == ScratchPad.recorded + end + + it "returns an empty array if no refinements defined in a module" do + Module.new.refinements.should == [] + end + end +end diff --git a/core/refinement/refined_class_spec.rb b/core/refinement/refined_class_spec.rb new file mode 100644 index 000000000..bcf48c4e2 --- /dev/null +++ b/core/refinement/refined_class_spec.rb @@ -0,0 +1,17 @@ +require_relative '../../spec_helper' + +describe "Refinement#refined_class" do + ruby_version_is "3.2" do + it "returns the class refined by the receiver" do + refinement_int = nil + + Module.new do + refine Integer do + refinement_int = self + end + end + + refinement_int.refined_class.should == Integer + end + end +end