require 'spec_helper' require 'captivus/backtrace' describe Captivus::Backtrace do def new_backtrace(*args) Captivus::Backtrace.new *args end describe ".new" do context "when the given object doesn't respond to `backtrace`" do it "raises an argument error" do object = double 'object' expect { new_backtrace object }.to raise_error(ArgumentError, "#{object} must respond to `backtrace`") end end end describe 'as_json' do before do @object = double 'object', :backtrace => ['/Users/x.rb:1', '/Users/x.rb:2', '/Users/x.rb:3'] end context "when the object has a backtrace" do it 'is an array of the backtrace lines as json' do new_backtrace(@object).as_json.should == [ Captivus::Backtrace::Line.new('/Users/x.rb:1').as_json, Captivus::Backtrace::Line.new('/Users/x.rb:2').as_json, Captivus::Backtrace::Line.new('/Users/x.rb:3').as_json ] end end context "when the object doesn't have a backtrace" do it "is an empty array" do @object.stub :backtrace new_backtrace(@object).as_json.should == [] end end end end