Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Removed Kernel#caller specs.

Every implementation uses significantly different methods to implement calling
methods. In MRI, numerous actual frames are invisible because they are in C,
while in Rubinius, these frames are in Ruby and are visible.

It's not realistic or useful to attempt to specify the results of caller.
Further, it's a hack in the first place and a proper object-oriented API for
querying the stack should be created.
  • Loading branch information...
commit 642bf529e988aef264e034a688fa81964ba3bd6b 1 parent 1398b36
@brixen brixen authored
View
108 core/kernel/caller_spec.rb
@@ -1,115 +1,7 @@
require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-# DO NOT PUT ANYTHING ABOVE THIS
describe "Kernel#caller" do
- before :each do
- def a(skip)
- caller(skip)
- end
- def b(skip)
- a(skip)
- end
- def c(skip)
- b(skip)
- end
- end
-
it "is a private method" do
Kernel.should have_private_instance_method(:caller)
end
-
- it "returns the current call stack" do
- stack = c 0
- stack[0].should =~ /caller_spec.rb.*?8.*?`a'/
- stack[1].should =~ /caller_spec.rb.*?11.*?`b'/
- stack[2].should =~ /caller_spec.rb.*?14.*?`c'/
- end
-
- it "omits a number of frames corresponding to the parameter" do
- c(0)[1..-1].should == c(1)
- c(0)[2..-1].should == c(2)
- c(0)[3..-1].should == c(3)
- end
-
- it "defaults to omitting one frame" do
- caller.should == caller(1)
- end
-
- # The contents of the array returned by #caller depends on whether
- # the call is made from an instance_eval block or a <block>#call.
- # We purposely do not spec what happens if you request to omit
- # more entries than exist in the array returned.
-end
-
-describe "Kernel#caller in a Proc or eval" do
- it "returns the definition trace of a block when evaluated in a Proc binding" do
- stack = CallerFixture.caller_of(CallerFixture.block)
- stack[0].should =~ /caller_fixture1\.rb:4:in `<top \(required\)>'/
- stack[1].should =~ /caller_fixture2\.rb:18:in `eval'/
- stack[2].should =~ /caller_fixture2\.rb:18:in `caller_of'/
- stack[3].should =~ /caller_spec\.rb:95:in `block \(3 levels\) in <top \(required\)>'/
- end
-
- it "returns the definition trace of a Proc" do
- stack = CallerFixture.caller_of(CallerFixture.example_proc)
- stack[0].should =~ /caller_fixture1\.rb:14:in `example_proc'/
- stack[1].should =~ /caller_fixture2\.rb:18:in `eval'/
- stack[2].should =~ /caller_fixture2\.rb:18:in `caller_of'/
- stack[3].should =~ /caller_spec\.rb:103:in `block \(3 levels\) in <top \(required\)>'/
- end
-
- it "returns the correct caller line from a called Proc" do
- stack = CallerFixture.entry_point.call
- stack[0].should =~ /caller_fixture1\.rb:31:in `block in third'/
- stack[1].should =~ /caller_spec\.rb:111:in `call'/
- stack[2].should =~ /caller_spec\.rb:111:in `block \(3 levels\) in <top \(required\)>'/
- end
-
- # On 1.8 this expectation is marred by bug #146. I don't understand 1.9's
- # output to ascertain whether the same bug occurs here, and if so what is
- # the correct behaviour
- it "returns the correct definition line for a complex Proc trace" do
- stack = CallerFixture.caller_of(CallerFixture.entry_point)
- stack[0].should =~ /caller_fixture1\.rb:29:in `third'/
- stack[1].should =~ /caller_fixture2\.rb:18:in `eval'/
- stack[2].should =~ /caller_fixture2\.rb:18:in `caller_of'/
- stack[3].should =~ /caller_spec.rb:121:in `block \(3 levels\) in <top \(required\)>'/
- end
-
- it "begins with (eval) for caller(0) in eval" do
- stack = CallerFixture.eval_caller(0)
- stack[0].should == "(eval):1:in `eval_caller'"
- stack[1].should =~ /caller_fixture2\.rb:23:in `eval'/
- stack[2].should =~ /caller_fixture2\.rb:23:in `eval_caller'/
- stack[3].should =~ /caller_spec\.rb:129:in `block \(3 levels\) in <top \(required\)>'/
- end
-
- it "shows the current line in the calling block twice when evaled" do
- stack = CallerFixture.eval_caller(0); line = __LINE__
- stack[0].should == "(eval):1:in `eval_caller'"
- stack[1].should =~/caller_fixture2\.rb:23:in `eval'/
- stack[2].should =~/caller_fixture2\.rb:23:in `eval_caller'/
- stack[3].should =~/caller_spec\.rb:#{line}:in `block \(3 levels\) in <top \(required\)>/
- end
-
- it "begins with the eval's sender's sender for caller(4) in eval" do
- stack = CallerFixture.eval_caller(4)
- stack[0].should =~ /\.rb:\d+:in `instance_eval'/ # mspec.rb
- end
-
- it "returns one frame for new and one frame for initialize when creating objects" do
- stack = CallerFixture::InitializeRecorder.new(0).caller_on_initialize
- stack[0].should =~ /initialize/
- stack[1].should =~ /new/
- end
-end
-
-describe "Kernel.caller" do
- # redmine:3011
- it "returns one entry per call, even for recursive methods" do
- two = CallerSpecs::recurse(2)
- three = CallerSpecs::recurse(3)
- (three.size - two.size).should == 1
- end
end
View
42 core/kernel/fixtures/caller_fixture1.rb
@@ -1,42 +0,0 @@
-require File.expand_path('../caller_fixture2', __FILE__)
-2 + 2
-3 + 3
-CallerFixture.capture do
- 5 + 5
- 6 + 6
- :seven
- 8 + 8
-end
-
-module CallerFixture
- module_function
- def example_proc
- Proc.new do
- 1 + 1
- 2 + 2
- end
- end
-
- def entry_point
- second
- end
-
- def second
- third
- end
-
- def third
- b = fourth do
- 1 + 1
- caller(0)
- end
- 2 + 2
- 3 + 3
- return b
- end
-
- def fourth(&block)
- return block
- end
-end
-
View
33 core/kernel/fixtures/caller_fixture2.rb
@@ -1,33 +0,0 @@
-module CallerFixture
- def block
- @block
- end
- module_function :block
-
- def block=(block)
- @block = block
- end
- module_function :block=
-
- def capture(&block)
- @block = block
- end
- module_function :capture
-
- def caller_of(block)
- eval("caller(0)", block.binding)
- end
- module_function :caller_of
-
- def eval_caller(depth)
- eval("caller(#{depth})")
- end
- module_function :eval_caller
-
- class InitializeRecorder
- attr_reader :caller_on_initialize
- def initialize(level)
- @caller_on_initialize = caller(level)
- end
- end
-end
View
9 core/kernel/fixtures/classes.rb
@@ -1,5 +1,3 @@
-require File.expand_path('../caller_fixture1', __FILE__)
-
module KernelSpecs
def self.Array_function(arg)
Array(arg)
@@ -439,13 +437,6 @@ def self.call_eval
end
end
-module CallerSpecs
- def self.recurse(n)
- return caller if n <= 0
- recurse(n-1)
- end
-end
-
# for Kernel#sleep to have Channel in it's specs
# TODO: switch directly to queue for both Kernel#sleep and Thread specs?
unless defined? Channel
Please sign in to comment.
Something went wrong with that request. Please try again.