Class: CI::Reporter::RSpec2::Failure

Inherits:
Object
  • Object
show all
Defined in:
lib/ci/reporter/rspec2/failure.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(example, formatter) ⇒ Failure

Returns a new instance of Failure.


6
7
8
9
10
11
12
13
14
# File 'lib/ci/reporter/rspec2/failure.rb', line 6

def initialize(example, formatter)
  @formatter = formatter
  @example = example
  if @example.respond_to?(:execution_result)
    @exception = @example.execution_result[:exception] || @example.execution_result[:exception_encountered]
  else
    @exception = @example.[:execution_result][:exception]
  end
end

Instance Attribute Details

#exceptionObject (readonly)

Returns the value of attribute exception.


4
5
6
# File 'lib/ci/reporter/rspec2/failure.rb', line 4

def exception
  @exception
end

Instance Method Details

#error?Boolean

Returns:

  • (Boolean)

28
29
30
# File 'lib/ci/reporter/rspec2/failure.rb', line 28

def error?
  !failure?
end

#failure?Boolean

Returns:

  • (Boolean)

24
25
26
# File 'lib/ci/reporter/rspec2/failure.rb', line 24

def failure?
  exception.is_a?(::RSpec::Expectations::ExpectationNotMetError)
end

#locationObject


32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ci/reporter/rspec2/failure.rb', line 32

def location
  output = []
  output.push "#{exception.class.name << ":"}" unless exception.class.name =~ /RSpec/
  output.push @exception.message

  [@formatter.format_backtrace(@exception.backtrace, @example)].flatten.each do |backtrace_info|
    backtrace_info.lines.each do |line|
      output.push "     #{line}"
    end
  end
  output.join "\n"
end

#messageObject


20
21
22
# File 'lib/ci/reporter/rspec2/failure.rb', line 20

def message
  @exception.message
end

#nameObject


16
17
18
# File 'lib/ci/reporter/rspec2/failure.rb', line 16

def name
  @exception.class.name
end