Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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