Class: Similatron::Comparison
- Inherits:
-
Object
- Object
- Similatron::Comparison
- Defined in:
- lib/similatron/comparison.rb
Instance Attribute Summary collapse
-
#actual ⇒ Object
readonly
Returns the value of attribute actual.
-
#diff ⇒ Object
readonly
Returns the value of attribute diff.
-
#expected ⇒ Object
readonly
Returns the value of attribute expected.
-
#score ⇒ Object
readonly
Returns the value of attribute score.
Instance Method Summary collapse
- #as_json ⇒ Object
-
#initialize(expected:, actual:, score:, diff: nil, overwrite: nil) ⇒ Comparison
constructor
A new instance of Comparison.
- #overwrite? ⇒ Boolean
- #raise_when_different ⇒ Object
- #same? ⇒ Boolean
Constructor Details
#initialize(expected:, actual:, score:, diff: nil, overwrite: nil) ⇒ Comparison
Returns a new instance of Comparison.
6 7 8 9 10 11 12 |
# File 'lib/similatron/comparison.rb', line 6 def initialize(expected:, actual:, score:, diff: nil, overwrite: nil) @expected = expected @actual = actual @diff = diff @score = score @overwrite = overwrite end |
Instance Attribute Details
#actual ⇒ Object (readonly)
Returns the value of attribute actual.
4 5 6 |
# File 'lib/similatron/comparison.rb', line 4 def actual @actual end |
#diff ⇒ Object (readonly)
Returns the value of attribute diff.
4 5 6 |
# File 'lib/similatron/comparison.rb', line 4 def diff @diff end |
#expected ⇒ Object (readonly)
Returns the value of attribute expected.
4 5 6 |
# File 'lib/similatron/comparison.rb', line 4 def expected @expected end |
#score ⇒ Object (readonly)
Returns the value of attribute score.
4 5 6 |
# File 'lib/similatron/comparison.rb', line 4 def score @score end |
Instance Method Details
#as_json ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/similatron/comparison.rb', line 34 def as_json { expected: expected, actual: actual, diff: diff, score: score, same: !!same?, # rubocop:disable Style/DoubleNegation overwrite: !!overwrite? # rubocop:disable Style/DoubleNegation } end |
#overwrite? ⇒ Boolean
18 19 20 |
# File 'lib/similatron/comparison.rb', line 18 def overwrite? @overwrite end |
#raise_when_different ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/similatron/comparison.rb', line 22 def raise_when_different return if same? = [ "Found #{actual} different from #{expected}\n", "Score: #{score}" ] << "\nDiff in #{diff}" if diff raise StandardError, .join end |
#same? ⇒ Boolean
14 15 16 |
# File 'lib/similatron/comparison.rb', line 14 def same? @score.zero? end |