Exception: Nitrous::AssertionFailedError

Inherits:
Exception
  • Object
show all
Defined in:
lib/nitrous/assertions.rb

Instance Method Summary collapse

Constructor Details

#initialize(message, filename) ⇒ AssertionFailedError

Returns a new instance of AssertionFailedError.



3
4
5
# File 'lib/nitrous/assertions.rb', line 3

def initialize(message, filename)
  @message, @filename = message, filename
end

Instance Method Details

#failure_locationObject



7
8
9
10
11
# File 'lib/nitrous/assertions.rb', line 7

def failure_location
  @failure_location ||= backtrace.detect do |line|
    line.include?(@filename)
  end
end

#snippetObject



13
14
15
16
17
18
19
20
21
22
# File 'lib/nitrous/assertions.rb', line 13

def snippet
  failure_location =~ /^([^:]+):(\d+)/
  index = $2.to_i - 1
  lines = File.readlines($1)
  "...\n" + 
  "   " + lines[index - 1] + 
  " >>" + lines[index]     + 
  "   " + lines[index + 1] + 
  "...\n"
end

#test_outputObject



24
25
26
# File 'lib/nitrous/assertions.rb', line 24

def test_output
  "Assertion failed on #{failure_location}\n#{@message}\n#{snippet}"
end