Skip to content

Commit 8721492

Browse files
kachickbrixen
authored andcommittedJul 22, 2016
Add a failing spec for a case then protected method called from public_send in own method (#3681)
* Add specs to call public_send via own public method ref: https://bugs.ruby-lang.org/issues/7499 * Add a failing tag for above * Adjust style with classic lambda syntax ref: #3681 (comment)
1 parent f0373ac commit 8721492

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed
 

‎spec/ruby/core/kernel/public_send_spec.rb

+34
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,40 @@ def bar
4444
}.should raise_error(NoMethodError)
4545
end
4646

47+
context 'called from own public method' do
48+
before do
49+
class << @receiver = Object.new
50+
def call_protected_method
51+
public_send :protected_method
52+
end
53+
54+
def call_private_method
55+
public_send :private_method
56+
end
57+
58+
protected
59+
60+
def protected_method
61+
raise 'Should not called'
62+
end
63+
64+
private
65+
66+
def private_method
67+
raise 'Should not called'
68+
end
69+
end
70+
end
71+
72+
it "raises a NoMethodError if the method is protected" do
73+
lambda { @receiver.call_protected_method }.should raise_error(NoMethodError)
74+
end
75+
76+
it "raises a NoMethodError if the method is private" do
77+
lambda { @receiver.call_private_method }.should raise_error(NoMethodError)
78+
end
79+
end
80+
4781
it "raises a NoMethodError if the named method is an alias of a private method" do
4882
class KernelSpecs::Foo
4983
alias :aka :bar
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fails:Kernel#public_send called from own public method raises a NoMethodError if the method is protected

0 commit comments

Comments
 (0)