Module: Probatio::ExtraErrorMethods

Defined in:
lib/probatio/errors.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#testObject

Returns the value of attribute test.



231
232
233
# File 'lib/probatio/errors.rb', line 231

def test
  @test
end

Instance Method Details

#lineObject



265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/probatio/errors.rb', line 265

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



235
# File 'lib/probatio/errors.rb', line 235

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

#locationObject



234
# File 'lib/probatio/errors.rb', line 234

def location; [ path, line ]; end

#pathObject



233
# File 'lib/probatio/errors.rb', line 233

def path; test.path; end

#source_linesObject



245
246
247
248
249
# File 'lib/probatio/errors.rb', line 245

def source_lines

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

#summary(indent = '') ⇒ Object



251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'lib/probatio/errors.rb', line 251

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



237
238
239
240
241
242
243
# File 'lib/probatio/errors.rb', line 237

def trail

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

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