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

Ruby 3.1: Add specs for Refinement#import_methods and deprecation of include/prepend #979

Merged
merged 1 commit into from
Dec 26, 2022
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
34 changes: 34 additions & 0 deletions core/refinement/import_methods_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require_relative '../../spec_helper'

describe "Refinement#import_methods" do
ruby_version_is "3.1" do
context "when methods are defined in Ruby code" do
it "imports methods" do
str_utils = Module.new do
def indent(level)
" " * level + self
end
end

Module.new do
refine String do
import_methods str_utils
"foo".indent(3).should == " foo"
end
end
end
end

context "when methods are not defined in Ruby code" do
it "raises ArgumentError" do
Module.new do
refine String do
-> {
import_methods Kernel
}.should raise_error(ArgumentError)
end
end
end
end
end
end
15 changes: 15 additions & 0 deletions core/refinement/include_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require_relative '../../spec_helper'

describe "Refinement#include" do
ruby_version_is "3.1" do
it "warns about deprecation" do
Module.new do
refine String do
-> {
include Module.new
}.should complain(/warning: Refinement#include is deprecated and will be removed in Ruby 3.2/)
end
end
end
end
end
15 changes: 15 additions & 0 deletions core/refinement/prepend_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require_relative '../../spec_helper'

describe "Refinement#prepend" do
ruby_version_is "3.1" do
it "warns about deprecation" do
Module.new do
refine String do
-> {
prepend Module.new
}.should complain(/warning: Refinement#prepend is deprecated and will be removed in Ruby 3.2/)
end
end
end
end
end