-
-
Notifications
You must be signed in to change notification settings - Fork 388
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add specs for Refinement#import_methods and deprecation of include/pr…
…epend
- Loading branch information
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |