Skip to content

Commit

Permalink
Merge pull request #1028 from AI-Mozi/add_specs_for_module_used_refin…
Browse files Browse the repository at this point in the history
…ements

Add specs for `Module.used_refinements`
  • Loading branch information
andrykonchin committed May 16, 2023
2 parents 2275adc + a5ae679 commit a3b248a
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions core/module/used_refinements_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
require_relative '../../spec_helper'

describe "Module.used_refinements" do
ruby_version_is "3.2" do
it "returns list of all refinements imported in the current scope" do
refinement_int = nil
refinement_str = nil
ScratchPad.record []

m1 = Module.new do
refine Integer do
refinement_int = self
end
end

m2 = Module.new do
refine String do
refinement_str = self
end
end

Module.new do
using m1
using m2

Module.used_refinements.each { |r| ScratchPad << r }
end

ScratchPad.recorded.sort_by(&:object_id).should == [refinement_int, refinement_str].sort_by(&:object_id)
end

it "returns empty array if does not have any refinements imported" do
used_refinements = nil

Module.new do
used_refinements = Module.used_refinements
end

used_refinements.should == []
end

it "ignores refinements imported in a module that is included into the current one" do
used_refinements = nil

m1 = Module.new do
refine Integer do
nil
end
end

m2 = Module.new do
using m1
end

Module.new do
include m2

used_refinements = Module.used_refinements
end

used_refinements.should == []
end

it "returns refinements even not defined directly in a module refinements are imported from" do
used_refinements = nil
ScratchPad.record []

m1 = Module.new do
refine Integer do
ScratchPad << self
end
end

m2 = Module.new do
include m1
end

Module.new do
using m2

used_refinements = Module.used_refinements
end

used_refinements.should == ScratchPad.recorded
end
end
end

0 comments on commit a3b248a

Please sign in to comment.