Exception: Probatio::AssertionError
- Inherits:
-
StandardError
- Object
- StandardError
- Probatio::AssertionError
- Defined in:
- lib/probatio/errors.rb
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
-
#assertion ⇒ Object
readonly
Returns the value of attribute assertion.
-
#file ⇒ Object
(also: #path)
readonly
Returns the value of attribute file.
-
#line ⇒ Object
readonly
Returns the value of attribute line.
-
#nested_error ⇒ Object
Returns the value of attribute nested_error.
-
#test ⇒ Object
readonly
Returns the value of attribute test.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(assertion, arguments, error_or_message, test, file, line) ⇒ AssertionError
constructor
A new instance of AssertionError.
- #loc ⇒ Object
- #location ⇒ Object
- #source_line ⇒ Object
- #source_lines ⇒ Object
- #summary(indent = '') ⇒ Object
- #to_s ⇒ Object
- #trail ⇒ Object
Constructor Details
#initialize(assertion, arguments, error_or_message, test, file, line) ⇒ AssertionError
Returns a new instance of AssertionError.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/probatio/errors.rb', line 14 def initialize(assertion, arguments, , test, file, line) @assertion = assertion @arguments = arguments @test = test @file = file @line = line if .is_a?(String) @msg = else @msg = "error while asserting: " + . @nested_error = end super(@msg) end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
9 10 11 |
# File 'lib/probatio/errors.rb', line 9 def arguments @arguments end |
#assertion ⇒ Object (readonly)
Returns the value of attribute assertion.
9 10 11 |
# File 'lib/probatio/errors.rb', line 9 def assertion @assertion end |
#file ⇒ Object (readonly) Also known as: path
Returns the value of attribute file.
9 10 11 |
# File 'lib/probatio/errors.rb', line 9 def file @file end |
#line ⇒ Object (readonly)
Returns the value of attribute line.
9 10 11 |
# File 'lib/probatio/errors.rb', line 9 def line @line end |
#nested_error ⇒ Object
Returns the value of attribute nested_error.
10 11 12 |
# File 'lib/probatio/errors.rb', line 10 def nested_error @nested_error end |
#test ⇒ Object (readonly)
Returns the value of attribute test.
9 10 11 |
# File 'lib/probatio/errors.rb', line 9 def test @test end |
Class Method Details
.select_source_lines(path, line) ⇒ Object
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/probatio/errors.rb', line 105 def select_source_lines(path, line) return [] unless path File.readlines(path).each_with_index.to_a[line - 1..-1] .map { |l, i| [ i + 1, l.rstrip ] } .take_while { |_, l| l = l.strip l.length > 0 && l != 'end' && l != '}' } end |
Instance Method Details
#loc ⇒ Object
39 40 41 42 |
# File 'lib/probatio/errors.rb', line 39 def loc location.map(&:to_s).join(':') end |
#location ⇒ Object
34 35 36 37 |
# File 'lib/probatio/errors.rb', line 34 def location [ @file, @line ] end |
#source_line ⇒ Object
55 56 57 58 59 |
# File 'lib/probatio/errors.rb', line 55 def source_line @source_line ||= File.readlines(@file)[@line - 1] end |
#source_lines ⇒ Object
61 62 63 64 65 |
# File 'lib/probatio/errors.rb', line 61 def source_lines @source_lines ||= Probatio::AssertionError.select_source_lines(@file, @line) end |
#summary(indent = '') ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/probatio/errors.rb', line 67 def summary(indent='') nl = "\n" + indent tw = Probatio.term_width - 4 - indent.length as = @arguments.find { |a| a.inspect.length > tw } ? @arguments.collect { |a| if (s0 = a.inspect).length < tw nl + ' ' + s0 + "\n" else s1 = StringIO.new; PP.pp(a, s1, tw) qualify_argument(a) + "\n" + indent + s1.string.gsub(/^(.*)$/) { " #{$1}" } end } : @arguments.collect(&:inspect) s = StringIO.new s << indent << @assertion << ':' case @arguments.collect(&:class) when [ Hash, Hash ] as.each_with_index { |a, i| s << nl << ' %d: %s' % [ i, a ] } output_hash_diff(indent, s) when [ Array, Array ] output_array_diff(indent, s) when [ String, String ] output_string_diff(indent, s) else as.each_with_index { |a, i| s << nl << ' %d: %s' % [ i, a ] } end s.string end |
#to_s ⇒ Object
44 45 46 47 |
# File 'lib/probatio/errors.rb', line 44 def to_s "#{self.class.name}: #{@msg}" end |