From 88045067e7ab258fafff8d052903cbf871a41510 Mon Sep 17 00:00:00 2001 From: ytjmt <46666464+ytjmt@users.noreply.github.com> Date: Sat, 24 Dec 2022 00:07:38 +0900 Subject: [PATCH] Add specs for Refinement#import_methods and deprecation of include/prepend --- core/refinement/import_methods_spec.rb | 34 ++++++++++++++++++++++++++ core/refinement/include_spec.rb | 15 ++++++++++++ core/refinement/prepend_spec.rb | 15 ++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 core/refinement/import_methods_spec.rb create mode 100644 core/refinement/include_spec.rb create mode 100644 core/refinement/prepend_spec.rb diff --git a/core/refinement/import_methods_spec.rb b/core/refinement/import_methods_spec.rb new file mode 100644 index 0000000000..1c526f5822 --- /dev/null +++ b/core/refinement/import_methods_spec.rb @@ -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 diff --git a/core/refinement/include_spec.rb b/core/refinement/include_spec.rb new file mode 100644 index 0000000000..6e64947b67 --- /dev/null +++ b/core/refinement/include_spec.rb @@ -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 diff --git a/core/refinement/prepend_spec.rb b/core/refinement/prepend_spec.rb new file mode 100644 index 0000000000..ba9b8ba400 --- /dev/null +++ b/core/refinement/prepend_spec.rb @@ -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