Exception: Scientist::Experiment::MismatchError
- Inherits:
-
Exception
- Object
- Exception
- Scientist::Experiment::MismatchError
- Defined in:
- lib/scientist/experiment.rb
Overview
A mismatch, raised when raise_on_mismatches is enabled.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Instance Method Summary collapse
- #format_observation(observation) ⇒ Object
-
#initialize(name, result) ⇒ MismatchError
constructor
A new instance of MismatchError.
-
#to_s ⇒ Object
The default formatting is nearly unreadable, so make it useful.
Constructor Details
#initialize(name, result) ⇒ MismatchError
Returns a new instance of MismatchError.
34 35 36 37 38 |
# File 'lib/scientist/experiment.rb', line 34 def initialize(name, result) @name = name @result = result super "experiment '#{name}' observations mismatched" end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
32 33 34 |
# File 'lib/scientist/experiment.rb', line 32 def name @name end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
32 33 34 |
# File 'lib/scientist/experiment.rb', line 32 def result @result end |
Instance Method Details
#format_observation(observation) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/scientist/experiment.rb', line 51 def format_observation(observation) observation.name + ":\n" + if observation.raised? lines = observation.exception.backtrace.map { |line| " #{line}" }.join("\n") " #{observation.exception.inspect}" + "\n" + lines else " #{observation.cleaned_value.inspect}" end end |
#to_s ⇒ Object
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.
44 45 46 47 48 49 |
# File 'lib/scientist/experiment.rb', line 44 def to_s super + ":\n" + format_observation(result.control) + "\n" + result.candidates.map { |candidate| format_observation(candidate) }.join("\n") + "\n" end |