Module: Probatio::ExtraErrorMethods

Defined in:
lib/probatio.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#testObject

Returns the value of attribute test.



869
870
871
# File 'lib/probatio.rb', line 869

def test
  @test
end

Instance Method Details

#lineObject



903
904
905
906
907
908
909
910
911
912
913
914
# File 'lib/probatio.rb', line 903

def line

  backtrace.each do |l|

    ss = l.split(':')

    next unless ss.find { |e| e == test.path }
    return ss.find { |e| e.match?(/^\d+$/) }.to_i
  end

  -1
end

#locObject



873
# File 'lib/probatio.rb', line 873

def loc; location.map(&:to_s).join(':'); end

#locationObject



872
# File 'lib/probatio.rb', line 872

def location; [ path, line ]; end

#pathObject



871
# File 'lib/probatio.rb', line 871

def path; test.path; end

#source_linesObject



883
884
885
886
887
# File 'lib/probatio.rb', line 883

def source_lines

  @source_lines ||=
    Probatio::AssertionError.select_source_lines(test.path, line)
end

#summary(indent = '') ⇒ Object



889
890
891
892
893
894
895
896
897
898
899
900
901
# File 'lib/probatio.rb', line 889

def summary(indent='')

  o = StringIO.new

  o << self.class.name << ': ' << self.message.inspect << "\n"

  i = backtrace.index { |l| l.match?(/\/lib\/probatio\.rb:/) } || -1

  backtrace[0..i]
    .inject(o) { |o, l| o << indent << l << "\n" }

  o.string
end

#trailObject



875
876
877
878
879
880
881
# File 'lib/probatio.rb', line 875

def trail

  msg = "#{self.class}: #{self.message.inspect}"

  @test.trail + "\n" +
  Probatio.c.red("#{'  ' * (test.depth + 1)}#{loc} --> #{msg}")
end