Skip to content

Commit

Permalink
Add specs for Module#refinements and Refinement#refined_class
Browse files Browse the repository at this point in the history
  • Loading branch information
AI-Mozi committed May 17, 2023
1 parent 9aa1cbf commit 256f3ea
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
45 changes: 45 additions & 0 deletions core/module/refinements_spec.rb
Original file line number Diff line number Diff line change
@@ -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 []

m2 = Module.new do
refine String do
ScratchPad << self
end

refine Array do
ScratchPad << self
end
end

m2.refinements.sort_by(&:object_id).should == ScratchPad.recorded.sort_by(&:object_id)
end

it "does not returns 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
17 changes: 17 additions & 0 deletions core/refinement/refined_class_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 256f3ea

Please sign in to comment.