diff options
Diffstat (limited to 'spec/ruby/core/refinement')
| -rw-r--r-- | spec/ruby/core/refinement/append_features_spec.rb | 4 | ||||
| -rw-r--r-- | spec/ruby/core/refinement/extend_object_spec.rb | 4 | ||||
| -rw-r--r-- | spec/ruby/core/refinement/import_methods_spec.rb | 36 | ||||
| -rw-r--r-- | spec/ruby/core/refinement/include_spec.rb | 2 | ||||
| -rw-r--r-- | spec/ruby/core/refinement/prepend_features_spec.rb | 4 | ||||
| -rw-r--r-- | spec/ruby/core/refinement/prepend_spec.rb | 2 | ||||
| -rw-r--r-- | spec/ruby/core/refinement/refined_class_spec.rb | 7 | ||||
| -rw-r--r-- | spec/ruby/core/refinement/shared/target.rb | 13 | ||||
| -rw-r--r-- | spec/ruby/core/refinement/target_spec.rb | 13 |
9 files changed, 47 insertions, 38 deletions
diff --git a/spec/ruby/core/refinement/append_features_spec.rb b/spec/ruby/core/refinement/append_features_spec.rb index f7e5f32bc1..cffc9ed308 100644 --- a/spec/ruby/core/refinement/append_features_spec.rb +++ b/spec/ruby/core/refinement/append_features_spec.rb @@ -2,7 +2,7 @@ require_relative '../../spec_helper' describe "Refinement#append_features" do it "is not defined" do - Refinement.should_not have_private_instance_method(:append_features) + Refinement.private_instance_methods(true).should_not.include?(:append_features) end it "is not called by Module#include" do @@ -11,7 +11,7 @@ describe "Refinement#append_features" do refine c do called = false define_method(:append_features){called = true} - proc{c.include(self)}.should raise_error(TypeError) + proc{c.include(self)}.should.raise(TypeError) called.should == false end end diff --git a/spec/ruby/core/refinement/extend_object_spec.rb b/spec/ruby/core/refinement/extend_object_spec.rb index 4da8b359cc..f6fe2a60ea 100644 --- a/spec/ruby/core/refinement/extend_object_spec.rb +++ b/spec/ruby/core/refinement/extend_object_spec.rb @@ -2,7 +2,7 @@ require_relative '../../spec_helper' describe "Refinement#extend_object" do it "is not defined" do - Refinement.should_not have_private_instance_method(:extend_object) + Refinement.private_instance_methods(true).should_not.include?(:extend_object) end it "is not called by Object#extend" do @@ -13,7 +13,7 @@ describe "Refinement#extend_object" do define_method(:extend_object) { called = true } -> { c.extend(self) - }.should raise_error(TypeError) + }.should.raise(TypeError) called.should == false end end diff --git a/spec/ruby/core/refinement/import_methods_spec.rb b/spec/ruby/core/refinement/import_methods_spec.rb index 13c0b1004c..bcb5e9b066 100644 --- a/spec/ruby/core/refinement/import_methods_spec.rb +++ b/spec/ruby/core/refinement/import_methods_spec.rb @@ -23,7 +23,7 @@ describe "Refinement#import_methods" do refine String do -> { import_methods Integer - }.should raise_error(TypeError, "wrong argument type Class (expected Module)") + }.should.raise(TypeError, "wrong argument type Class (expected Module)") end end end @@ -82,7 +82,7 @@ describe "Refinement#import_methods" do refine String do -> { import_methods str_utils, Kernel - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) end end @@ -127,7 +127,7 @@ describe "Refinement#import_methods" do using self -> { "foo".indent(3) - }.should raise_error(NoMethodError, /undefined method [`']indent' for ("foo":String|an instance of String)/) + }.should.raise(NoMethodError, /undefined method [`']indent' for ("foo":String|an instance of String)/) end end @@ -142,7 +142,7 @@ describe "Refinement#import_methods" do refine String do -> { import_methods str_utils, Integer - }.should raise_error(TypeError) + }.should.raise(TypeError) end end @@ -150,7 +150,7 @@ describe "Refinement#import_methods" do using string_refined -> { "foo".indent(3) - }.should raise_error(NoMethodError) + }.should.raise(NoMethodError) end end @@ -213,7 +213,7 @@ describe "Refinement#import_methods" do using self -> { String.indent(3) - }.should raise_error(NoMethodError, /undefined method [`']indent' for (String:Class|class String)/) + }.should.raise(NoMethodError, /undefined method [`']indent' for (String:Class|class String)/) end end @@ -242,13 +242,33 @@ describe "Refinement#import_methods" do end end + it "correctly sets owner as the refinement module" do + str_utils = Module.new do + def indent(level) + " " * level + self + end + end + + refinement = Module.new do + refine String do + import_methods str_utils + end + end + + Module.new do + using refinement + + String.instance_method(:indent).owner.should == refinement.refinements.first + 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) + }.should.raise(ArgumentError) end end end @@ -259,7 +279,7 @@ describe "Refinement#import_methods" do refine String do -> { import_methods Zlib - }.should raise_error(ArgumentError, /Can't import method which is not defined with Ruby code: Zlib#*/) + }.should.raise(ArgumentError, /Can't import method which is not defined with Ruby code: Zlib#*/) end end end diff --git a/spec/ruby/core/refinement/include_spec.rb b/spec/ruby/core/refinement/include_spec.rb index 57451bd9bc..55ac89ffb5 100644 --- a/spec/ruby/core/refinement/include_spec.rb +++ b/spec/ruby/core/refinement/include_spec.rb @@ -6,7 +6,7 @@ describe "Refinement#include" do refine String do -> { include Module.new - }.should raise_error(TypeError, "Refinement#include has been removed") + }.should.raise(TypeError, "Refinement#include has been removed") end end end diff --git a/spec/ruby/core/refinement/prepend_features_spec.rb b/spec/ruby/core/refinement/prepend_features_spec.rb index fbc431bbd2..9dc5838f1f 100644 --- a/spec/ruby/core/refinement/prepend_features_spec.rb +++ b/spec/ruby/core/refinement/prepend_features_spec.rb @@ -2,7 +2,7 @@ require_relative '../../spec_helper' describe "Refinement#prepend_features" do it "is not defined" do - Refinement.should_not have_private_instance_method(:prepend_features) + Refinement.private_instance_methods(true).should_not.include?(:prepend_features) end it "is not called by Module#prepend" do @@ -11,7 +11,7 @@ describe "Refinement#prepend_features" do refine c do called = false define_method(:prepend_features){called = true} - proc{c.prepend(self)}.should raise_error(TypeError) + proc{c.prepend(self)}.should.raise(TypeError) called.should == false end end diff --git a/spec/ruby/core/refinement/prepend_spec.rb b/spec/ruby/core/refinement/prepend_spec.rb index 64cf7cd17f..fd70dd6f97 100644 --- a/spec/ruby/core/refinement/prepend_spec.rb +++ b/spec/ruby/core/refinement/prepend_spec.rb @@ -6,7 +6,7 @@ describe "Refinement#prepend" do refine String do -> { prepend Module.new - }.should raise_error(TypeError, "Refinement#prepend has been removed") + }.should.raise(TypeError, "Refinement#prepend has been removed") end end end diff --git a/spec/ruby/core/refinement/refined_class_spec.rb b/spec/ruby/core/refinement/refined_class_spec.rb index 60a58380cc..90f8d963d8 100644 --- a/spec/ruby/core/refinement/refined_class_spec.rb +++ b/spec/ruby/core/refinement/refined_class_spec.rb @@ -1,12 +1,7 @@ require_relative "../../spec_helper" -require_relative 'shared/target' describe "Refinement#refined_class" do - ruby_version_is ""..."3.3" do - it_behaves_like :refinement_target, :refined_class - end - - ruby_version_is "3.3"..."3.4" do + ruby_version_is ""..."3.4" do it "has been deprecated in favour of Refinement#target" do refinement_int = nil diff --git a/spec/ruby/core/refinement/shared/target.rb b/spec/ruby/core/refinement/shared/target.rb deleted file mode 100644 index 79557bea0b..0000000000 --- a/spec/ruby/core/refinement/shared/target.rb +++ /dev/null @@ -1,13 +0,0 @@ -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 diff --git a/spec/ruby/core/refinement/target_spec.rb b/spec/ruby/core/refinement/target_spec.rb index fee9588a96..eaee71e8c6 100644 --- a/spec/ruby/core/refinement/target_spec.rb +++ b/spec/ruby/core/refinement/target_spec.rb @@ -1,8 +1,15 @@ require_relative "../../spec_helper" -require_relative 'shared/target' describe "Refinement#target" do - ruby_version_is "3.3" do - it_behaves_like :refinement_target, :target + 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.target.should == Integer end end |
