Skip to content

Commit d0f5ad9

Browse files
committed
Spec that respond_to_missing? and method_missing are called with a Symbol name from Kernel#method
1 parent 1029a88 commit d0f5ad9

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

spec/ruby/core/kernel/fixtures/classes.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -362,18 +362,19 @@ class SuperAmpersand
362362
class RespondViaMissing
363363
def respond_to_missing?(method, priv=false)
364364
case method
365-
when :handled_publicly
366-
true
367-
when :handled_privately
368-
priv
369-
when :not_handled
370-
false
371-
else
372-
raise "Typo in method name"
365+
when :handled_publicly
366+
true
367+
when :handled_privately
368+
priv
369+
when :not_handled
370+
false
371+
else
372+
raise "Typo in method name: #{method.inspect}"
373373
end
374374
end
375375

376376
def method_missing(method, *args)
377+
raise "the method name should be a Symbol" unless Symbol === method
377378
"Done #{method}(#{args})"
378379
end
379380
end

spec/ruby/core/kernel/shared/method.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,18 @@ class KernelSpecs::Foo; def self.bar; 'class done'; end; end
1515
m.call.should == 'class done'
1616
end
1717

18-
it "returns a method object if we repond_to_missing? method" do
18+
it "returns a method object if respond_to_missing?(method) is true" do
1919
m = KernelSpecs::RespondViaMissing.new.send(@method, :handled_publicly)
2020
m.should be_an_instance_of Method
2121
m.call(42).should == "Done handled_publicly([42])"
2222
end
2323

24+
it "the returned method object if respond_to_missing?(method) calls #method_missing with a Symbol name" do
25+
m = KernelSpecs::RespondViaMissing.new.send(@method, "handled_publicly")
26+
m.should be_an_instance_of Method
27+
m.call(42).should == "Done handled_publicly([42])"
28+
end
29+
2430
it "raises a NameError for an invalid method name" do
2531
class KernelSpecs::Foo; def bar; 'done'; end; end
2632
-> {

0 commit comments

Comments
 (0)