Class: ExceptionState

Inherits:
Object show all
Defined in:
lib/extensions/mspec/mspec/runner/exception.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(state, location, exception) ⇒ ExceptionState

Returns a new instance of ExceptionState.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/extensions/mspec/mspec/runner/exception.rb', line 7

def initialize(state, location, exception)
  @exception = exception

  @description = location ? "An exception occurred during: #{location}" : ""
  if state
    @description += "\n" unless @description.empty?
    @description += state.description
    @describe = state.describe
    @it = state.it
  else
    @describe = @it = ""
  end
end

Instance Attribute Details

#describeObject (readonly)

Returns the value of attribute describe.



5
6
7
# File 'lib/extensions/mspec/mspec/runner/exception.rb', line 5

def describe
  @describe
end

#descriptionObject (readonly)

Returns the value of attribute description.



5
6
7
# File 'lib/extensions/mspec/mspec/runner/exception.rb', line 5

def description
  @description
end

#exceptionObject (readonly)

Returns the value of attribute exception.



5
6
7
# File 'lib/extensions/mspec/mspec/runner/exception.rb', line 5

def exception
  @exception
end

#itObject (readonly)

Returns the value of attribute it.



5
6
7
# File 'lib/extensions/mspec/mspec/runner/exception.rb', line 5

def it
  @it
end

Instance Method Details

#backtraceObject



36
37
38
39
40
41
42
# File 'lib/extensions/mspec/mspec/runner/exception.rb', line 36

def backtrace
  @backtrace_filter ||= MSpecScript.config[:backtrace_filter]

  bt = @exception.backtrace || []

  bt.select { |line| $MSPEC_DEBUG or @backtrace_filter !~ line }.join("\n")
end

#failure?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/extensions/mspec/mspec/runner/exception.rb', line 21

def failure?
  [SpecExpectationNotMetError, SpecExpectationNotFoundError].any? { |e| @exception.is_a? e }
end

#messageObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/extensions/mspec/mspec/runner/exception.rb', line 25

def message
  if @exception.message.empty?
    "<No message>"
  elsif @exception.class == SpecExpectationNotMetError ||
        @exception.class == SpecExpectationNotFoundError
    @exception.message
  else
    "#{@exception.class}: #{@exception.message}"
  end
end