Skip to content

Commit

Permalink
Add specs for Refinement#target
Browse files Browse the repository at this point in the history
This includes some additional updates:

* Move old specs for refined_class to a shared spec, use this shared
  spec for target
* Add a spec for Ruby 3.3 to check that refinement_target has been
  deprecated
* Add a spec for Ruby 3.4 to check that refinement_target has been
  removed
  • Loading branch information
herwinw authored and andrykonchin committed Nov 27, 2024
1 parent caa743e commit 11d86bd
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
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

0 comments on commit 11d86bd

Please sign in to comment.