Exception: Scientist::Experiment::MismatchError
- Inherits:
-
StandardError
- Object
- StandardError
- 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.
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
#name ⇒ Object (readonly)
Returns the value of attribute name.
22 23 24 |
# File 'lib/scientist/experiment.rb', line 22 def name @name end |
#result ⇒ Object (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_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.
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 |