Exception: Scientist::Experiment::MismatchError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/scientist/experiment.rb

Overview

A mismatch, raised when raise_on_mismatches is enabled.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, result) ⇒ MismatchError

Returns a new instance of MismatchError.



24
25
26
27
28
# File 'lib/scientist/experiment.rb', line 24

def initialize(name, result)
  @name   = name
  @result = result
  super "experiment '#{name}' observations mismatched"
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



22
23
24
# File 'lib/scientist/experiment.rb', line 22

def name
  @name
end

#resultObject (readonly)

Returns the value of attribute result.



22
23
24
# File 'lib/scientist/experiment.rb', line 22

def result
  @result
end

Instance Method Details

#format_observation(observation) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/scientist/experiment.rb', line 41

def format_observation(observation)
  observation.name + ":\n" +
  if observation.raised?
    observation.exception.inspect.prepend("  ") + "\n" +
      observation.exception.backtrace.map { |line| line.prepend("    ") }.join("\n")
  else
    observation.cleaned_value.inspect.prepend("  ")
  end
end

#to_sObject

The default formatting is nearly unreadable, so make it useful.

The assumption here is that errors raised in a test environment are printed out as strings, rather than using #inspect.



34
35
36
37
38
39
# File 'lib/scientist/experiment.rb', line 34

def to_s
  super + ":\n" +
  format_observation(result.control) + "\n" +
  result.candidates.map { |candidate| format_observation(candidate) }.join("\n") +
  "\n"
end