Class: Loupe::Failure

Inherits:
Object
  • Object
show all
Defined in:
lib/loupe/failure.rb

Overview

Failure

This class represents a single test failure. It corresponds to one method that was executed and had failed expectations.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(test, message) ⇒ Loupe::Failure

Parameters:



27
28
29
30
31
32
33
34
# File 'lib/loupe/failure.rb', line 27

def initialize(test, message)
  @file_name = test.file
  @test_name = test.name
  @line_number = test.line_number
  @klass = test.class
  @color = test.color
  @message = message
end

Instance Attribute Details

#file_nameString (readonly)

Returns:

  • (String)


10
11
12
# File 'lib/loupe/failure.rb', line 10

def file_name
  @file_name
end

#klassClass (readonly)

Returns:

  • (Class)


22
23
24
# File 'lib/loupe/failure.rb', line 22

def klass
  @klass
end

#line_numberInteger (readonly)

Returns:

  • (Integer)


19
20
21
# File 'lib/loupe/failure.rb', line 19

def line_number
  @line_number
end

#messageString (readonly)

Returns:

  • (String)


16
17
18
# File 'lib/loupe/failure.rb', line 16

def message
  @message
end

#test_nameString (readonly)

Returns:

  • (String)


13
14
15
# File 'lib/loupe/failure.rb', line 13

def test_name
  @test_name
end

Instance Method Details

#location_and_messageArray<String>

Returns:

  • (Array<String>)


42
43
44
45
46
47
# File 'lib/loupe/failure.rb', line 42

def location_and_message
  [
    "#{file_name}:#{line_number} at #{@color.p(test_name, :yellow)}",
    message
  ]
end

#to_sString

Returns:

  • (String)


37
38
39
# File 'lib/loupe/failure.rb', line 37

def to_s
  "#{file_name}:#{line_number} at #{@color.p(test_name, :yellow)}. #{message}"
end