aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authoreregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-20 22:02:10 +0000
committereregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-20 22:02:10 +0000
commit789b421665239974ffb7d65092cd17766d34169b (patch)
treefa47dd96a029a92bdd893f0aff60e930711f5195 /spec
parentb9259b1dc3ccd53c0d5e717876a1a6e6ef69e79d (diff)
downloadruby-789b421665239974ffb7d65092cd17766d34169b.tar.gz
check_funcall_missing() should call respond_to_missing?(name, priv=true)
* Improve spec rather than constrain implementation. * Coercion ignores visibility in Ruby. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59982 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec')
-rw-r--r--spec/ruby/core/array/flatten_spec.rb24
1 files changed, 20 insertions, 4 deletions
diff --git a/spec/ruby/core/array/flatten_spec.rb b/spec/ruby/core/array/flatten_spec.rb
index 554b711a55..3b20e976b6 100644
--- a/spec/ruby/core/array/flatten_spec.rb
+++ b/spec/ruby/core/array/flatten_spec.rb
@@ -111,18 +111,34 @@ describe "Array#flatten" do
lambda { [@obj].flatten }.should raise_error(TypeError)
end
+ ruby_version_is ""..."2.5" do
+ it "calls respond_to_missing?(:to_ary, false) to try coercing" do
+ def @obj.respond_to_missing?(*args) ScratchPad << args; false end
+ [@obj].flatten.should == [@obj]
+ ScratchPad.recorded.should == [[:to_ary, false]]
+ end
+ end
+
+ ruby_version_is "2.5" do
+ it "calls respond_to_missing?(:to_ary, true) to try coercing" do
+ def @obj.respond_to_missing?(*args) ScratchPad << args; false end
+ [@obj].flatten.should == [@obj]
+ ScratchPad.recorded.should == [[:to_ary, true]]
+ end
+ end
+
it "does not call #to_ary if not defined when #respond_to_missing? returns false" do
- def @obj.respond_to_missing?(*args) ScratchPad << args; false end
+ def @obj.respond_to_missing?(name, priv) ScratchPad << name; false end
[@obj].flatten.should == [@obj]
- ScratchPad.recorded.should == [[:to_ary, false]]
+ ScratchPad.recorded.should == [:to_ary]
end
it "calls #to_ary if not defined when #respond_to_missing? returns true" do
- def @obj.respond_to_missing?(*args) ScratchPad << args; true end
+ def @obj.respond_to_missing?(name, priv) ScratchPad << name; true end
lambda { [@obj].flatten }.should raise_error(NoMethodError)
- ScratchPad.recorded.should == [[:to_ary, false]]
+ ScratchPad.recorded.should == [:to_ary]
end
it "calls #method_missing if defined" do