1require_relative '../../spec_helper'
2require_relative 'fixtures/common'
3
4describe "Exception#backtrace_locations" do
5  before :each do
6    @backtrace = ExceptionSpecs::Backtrace.backtrace_locations
7  end
8
9  it "returns nil if no backtrace was set" do
10    Exception.new.backtrace_locations.should be_nil
11  end
12
13  it "returns an Array" do
14    @backtrace.should be_an_instance_of(Array)
15  end
16
17  it "sets each element to a Thread::Backtrace::Location" do
18    @backtrace.each {|l| l.should be_an_instance_of(Thread::Backtrace::Location)}
19  end
20
21  it "produces a backtrace for an exception captured using $!" do
22    exception = begin
23      raise
24    rescue RuntimeError
25      $!
26    end
27
28    exception.backtrace_locations.first.path.should =~ /backtrace_locations_spec/
29  end
30
31  it "returns an Array that can be updated" do
32    begin
33      raise
34    rescue RuntimeError => e
35      e.backtrace_locations.unshift "backtrace first"
36      e.backtrace_locations[0].should == "backtrace first"
37    end
38  end
39end
40