Skip to content

Commit

Permalink
Add specs for Refinement#import_methods and deprecation of include/pr…
Browse files Browse the repository at this point in the history
…epend
  • Loading branch information
ytjmt committed Dec 26, 2022
1 parent 72872a7 commit 8804506
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
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

0 comments on commit 8804506

Please sign in to comment.