class RSpec::Core::Example::ExecutionResult

Represents the result of executing an example. Behaves like a hash for backwards compatibility.

Attributes

exception[RW]

@return [Exception, nil] The failure, if there was one.

finished_at[RW]

@return [Time] When the example finished.

pending_exception[RW]

@return [Exception, nil] The exception triggered while

executing the pending example. If no exception was triggered
it would no longer get a status of `:pending` unless it was
tagged with `:skip`.
pending_fixed[RW]

@return [Boolean] For examples tagged with ‘:pending`,

this indicates whether or not it now passes.
pending_message[RW]

@return [String, nil] The reason the example was pending,

or nil if the example was not pending.
run_time[RW]

@return [Float] How long the example took in seconds.

started_at[RW]

@return [Time] When the example started.

status[RW]

@return [Symbol] ‘:passed`, `:failed` or `:pending`.

Public Instance Methods

ensure_timing_set(clock) click to toggle source

@api private Populates finished_at and run_time if it has not yet been set

# File lib/rspec/core/example.rb, line 610
def ensure_timing_set(clock)
  calculate_run_time(clock.now) unless finished_at
end
example_skipped?() click to toggle source

@return [Boolean] Indicates if the example was completely skipped

(typically done via `:skip` metadata or the `skip` method). Skipped examples
will have a `:pending` result. A `:pending` result can also come from examples
that were marked as `:pending`, which causes them to be run, and produces a
`:failed` result if the example passes.
# File lib/rspec/core/example.rb, line 597
def example_skipped?
  status == :pending && !pending_exception
end
pending_fixed?() click to toggle source
# File lib/rspec/core/example.rb, line 588
def pending_fixed?
  !!pending_fixed
end
record_finished(status, finished_at) click to toggle source

@api private Records the finished status of the example.

# File lib/rspec/core/example.rb, line 603
def record_finished(status, finished_at)
  self.status = status
  calculate_run_time(finished_at)
end

Private Instance Methods

calculate_run_time(finished_at) click to toggle source
# File lib/rspec/core/example.rb, line 616
def calculate_run_time(finished_at)
  self.finished_at = finished_at
  self.run_time    = (finished_at - started_at).to_f
end
get_value(name) click to toggle source
Calls superclass method RSpec::Core::HashImitatable#get_value
# File lib/rspec/core/example.rb, line 634
def get_value(name)
  if name == :status
    status.to_s if status
  else
    super
  end
end
hash_for_delegation() click to toggle source

For backwards compatibility we present ‘status` as a string when presenting the legacy hash interface.

# File lib/rspec/core/example.rb, line 623
def hash_for_delegation
  super.tap do |hash|
    hash[:status] &&= status.to_s
  end
end
issue_deprecation(_method_name, *_args) click to toggle source
# File lib/rspec/core/example.rb, line 642
def issue_deprecation(_method_name, *_args)
  RSpec.deprecate("Treating `metadata[:execution_result]` as a hash",
                  :replacement => "the attributes methods to access the data")
end
set_value(name, value) click to toggle source
Calls superclass method RSpec::Core::HashImitatable#set_value
# File lib/rspec/core/example.rb, line 629
def set_value(name, value)
  value &&= value.to_sym if name == :status
  super(name, value)
end