Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add specs for Module#refinements and Refinement#refined_class #1027

Merged
Merged
Show file tree
Hide file tree
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
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 []

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
andrykonchin marked this conversation as resolved.
Show resolved Hide resolved
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
andrykonchin marked this conversation as resolved.
Show resolved Hide resolved
end
end