diff options
Diffstat (limited to 'spec/ruby/core/kernel/method_spec.rb')
-rw-r--r-- | spec/ruby/core/kernel/method_spec.rb | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/spec/ruby/core/kernel/method_spec.rb b/spec/ruby/core/kernel/method_spec.rb index caf2ec948b..3fc566d6a6 100644 --- a/spec/ruby/core/kernel/method_spec.rb +++ b/spec/ruby/core/kernel/method_spec.rb @@ -29,7 +29,7 @@ describe "Kernel#method" do m.call.should == :defined end - it "can be called even if we only repond_to_missing? method, true" do + it "can be called even if we only respond_to_missing? method, true" do m = KernelSpecs::RespondViaMissing.new.method(:handled_privately) m.should be_an_instance_of(Method) m.call(1, 2, 3).should == "Done handled_privately([1, 2, 3])" @@ -58,4 +58,23 @@ describe "Kernel#method" do m = cls.new.method(:bar) m.call.should == :bar end + + describe "converts the given name to a String using #to_str" do + it "calls #to_str to convert the given name to a String" do + name = mock("method-name") + name.should_receive(:to_str).and_return("hash") + Object.method(name).should == Object.method(:hash) + end + + it "raises a TypeError if the given name can't be converted to a String" do + -> { Object.method(nil) }.should raise_error(TypeError) + -> { Object.method([]) }.should raise_error(TypeError) + end + + it "raises a NoMethodError if the given argument raises a NoMethodError during type coercion to a String" do + name = mock("method-name") + name.should_receive(:to_str).and_raise(NoMethodError) + -> { Object.method(name) }.should raise_error(NoMethodError) + end + end end |