summaryrefslogtreecommitdiff
path: root/spec/ruby/core/method/call_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/method/call_spec.rb')
-rw-r--r--spec/ruby/core/method/call_spec.rb51
1 files changed, 49 insertions, 2 deletions
diff --git a/spec/ruby/core/method/call_spec.rb b/spec/ruby/core/method/call_spec.rb
index 6d997325fa..cb11545e91 100644
--- a/spec/ruby/core/method/call_spec.rb
+++ b/spec/ruby/core/method/call_spec.rb
@@ -1,7 +1,54 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
-require_relative 'shared/call'
describe "Method#call" do
- it_behaves_like :method_call, :call
+ it "invokes the method with the specified arguments, returning the method's return value" do
+ m = 12.method("+")
+ m.call(3).should == 15
+ m.call(20).should == 32
+
+ m = MethodSpecs::Methods.new.method(:attr=)
+ m.call(42).should == 42
+ end
+
+ it "raises an ArgumentError when given incorrect number of arguments" do
+ -> {
+ MethodSpecs::Methods.new.method(:two_req).call(1, 2, 3)
+ }.should.raise(ArgumentError)
+ -> {
+ MethodSpecs::Methods.new.method(:two_req).call(1)
+ }.should.raise(ArgumentError)
+ end
+
+ describe "for a Method generated by respond_to_missing?" do
+ it "invokes method_missing with the specified arguments and returns the result" do
+ @m = MethodSpecs::Methods.new
+ meth = @m.method(:handled_via_method_missing)
+ meth.call(:argument).should == [:argument]
+ end
+
+ it "invokes method_missing with the method name and the specified arguments" do
+ @m = MethodSpecs::Methods.new
+ meth = @m.method(:handled_via_method_missing)
+
+ @m.should_receive(:method_missing).with(:handled_via_method_missing, :argument)
+ meth.call(:argument)
+ end
+
+ it "invokes method_missing dynamically" do
+ @m = MethodSpecs::Methods.new
+ meth = @m.method(:handled_via_method_missing)
+
+ def @m.method_missing(*); :changed; end
+ meth.call(:argument).should == :changed
+ end
+
+ it "does not call the original method name even if it now exists" do
+ @m = MethodSpecs::Methods.new
+ meth = @m.method(:handled_via_method_missing)
+
+ def @m.handled_via_method_missing(*); :not_called; end
+ meth.call(:argument).should == [:argument]
+ end
+ end
end