Class: RSpec::Jasmine::ExampleResult

Inherits:
Hash
  • Object
show all
Defined in:
lib/rspec/jasmine/example_result.rb

Instance Method Summary collapse

Constructor Details

#initialize(results) ⇒ ExampleResult

Returns a new instance of ExampleResult.



4
5
6
7
# File 'lib/rspec/jasmine/example_result.rb', line 4

def initialize(results)
  super()
  merge!(results)
end

Instance Method Details

#backtraceObject



31
32
33
34
35
36
# File 'lib/rspec/jasmine/example_result.rb', line 31

def backtrace
  trace = failure['trace'] || {}
  trace['stack'].to_s.split(/$/).map(&:strip).delete_if do |line|
    line =~ /\/lib\/jasmine-\d+\.\d+\.\d+\/jasmine\.js\:\d+/ || line.strip.empty?
  end
end

#error_messageObject



17
18
19
# File 'lib/rspec/jasmine/example_result.rb', line 17

def error_message
  failure['message'].to_s
end

#failed?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/rspec/jasmine/example_result.rb', line 9

def failed?
  self['result'] == 'failed'
end

#failureObject



13
14
15
# File 'lib/rspec/jasmine/example_result.rb', line 13

def failure
  @failed_message ||= self['messages'].to_a.find { |m| m['passed'] == false }
end

#merge_backtrace_with!(e) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/rspec/jasmine/example_result.rb', line 21

def merge_backtrace_with!(e)
  e.instance_variable_set('@stack', self.backtrace)
  
  class << e
    def backtrace
      return @stack
    end
  end
end

#scream!Object



38
39
40
41
42
# File 'lib/rspec/jasmine/example_result.rb', line 38

def scream!
  if failed?
    raise RSpec::Expectations::ExpectationNotMetError.new(error_message)
  end
end