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 Refinement#target #1220

Merged
merged 1 commit into from
Nov 27, 2024
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
27 changes: 24 additions & 3 deletions core/refinement/refined_class_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
require_relative '../../spec_helper'
require_relative "../../spec_helper"
require_relative 'shared/target'

describe "Refinement#refined_class" do
ruby_version_is "3.2"..."3.3" do
it "returns the class refined by the receiver" do
it_behaves_like :refinement_target, :refined_class
end

ruby_version_is "3.3"..."3.4" do
it "has been deprecated in favour of Refinement#target" do
refinement_int = nil

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

-> {
refinement_int.refined_class
}.should complain(/warning: Refinement#refined_class is deprecated and will be removed in Ruby 3.4; use Refinement#target instead/)
end
end

ruby_version_is "3.4" do
it "has been removed" do
refinement_int = nil

Module.new do
Expand All @@ -11,7 +32,7 @@
end
end

refinement_int.refined_class.should == Integer
refinement_int.should_not.respond_to?(:refined_class)
end
end
end
13 changes: 13 additions & 0 deletions core/refinement/shared/target.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
describe :refinement_target, shared: true 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.send(@method).should == Integer
end
end
8 changes: 8 additions & 0 deletions core/refinement/target_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require_relative "../../spec_helper"
require_relative 'shared/target'

describe "Refinement#target" do
ruby_version_is "3.3" do
it_behaves_like :refinement_target, :target
end
end