Class: Backspin::CommandDiff
- Inherits:
-
Object
- Object
- Backspin::CommandDiff
- Defined in:
- lib/backspin/command_diff.rb
Overview
Represents the difference between expected and actual snapshots.
Defined Under Namespace
Classes: ComparisonSnapshot
Instance Attribute Summary collapse
-
#actual ⇒ Object
readonly
Returns the value of attribute actual.
-
#expected ⇒ Object
readonly
Returns the value of attribute expected.
-
#matcher ⇒ Object
readonly
Returns the value of attribute matcher.
Instance Method Summary collapse
-
#diff ⇒ String?
Human-readable diff if not verified.
-
#initialize(expected:, actual:, matcher: nil, filter: nil, filter_on: :both) ⇒ CommandDiff
constructor
A new instance of CommandDiff.
-
#summary ⇒ String
Single line summary for error messages.
-
#verified? ⇒ Boolean
True if the snapshot output matches.
Constructor Details
#initialize(expected:, actual:, matcher: nil, filter: nil, filter_on: :both) ⇒ CommandDiff
Returns a new instance of CommandDiff.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/backspin/command_diff.rb', line 8 def initialize(expected:, actual:, matcher: nil, filter: nil, filter_on: :both) @expected = expected @actual = actual @expected_compare = build_comparison_snapshot(expected, filter: filter, filter_on: filter_on) @actual_compare = build_comparison_snapshot(actual, filter: filter, filter_on: filter_on) @matcher = Matcher.new( config: matcher, expected: @expected_compare, actual: @actual_compare ) @verified = nil end |
Instance Attribute Details
#actual ⇒ Object (readonly)
Returns the value of attribute actual.
6 7 8 |
# File 'lib/backspin/command_diff.rb', line 6 def actual @actual end |
#expected ⇒ Object (readonly)
Returns the value of attribute expected.
6 7 8 |
# File 'lib/backspin/command_diff.rb', line 6 def expected @expected end |
#matcher ⇒ Object (readonly)
Returns the value of attribute matcher.
6 7 8 |
# File 'lib/backspin/command_diff.rb', line 6 def matcher @matcher end |
Instance Method Details
#diff ⇒ String?
Returns Human-readable diff if not verified.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/backspin/command_diff.rb', line 30 def diff return nil if verified? parts = [] unless command_types_match? parts << "Command type mismatch: expected #{expected.command_type.name}, got #{actual.command_type.name}" end if expected_compare.stdout != actual_compare.stdout parts << stdout_diff(expected_compare.stdout, actual_compare.stdout) end if expected_compare.stderr != actual_compare.stderr parts << stderr_diff(expected_compare.stderr, actual_compare.stderr) end if expected_compare.status != actual_compare.status parts << "Exit status: expected #{expected_compare.status}, got #{actual_compare.status}" end parts.join("\n\n") end |
#summary ⇒ String
Returns Single line summary for error messages.
55 56 57 58 59 60 61 |
# File 'lib/backspin/command_diff.rb', line 55 def summary if verified? "✓ Command verified" else "✗ Command failed: #{failure_reason}" end end |
#verified? ⇒ Boolean
Returns true if the snapshot output matches.
22 23 24 25 26 27 |
# File 'lib/backspin/command_diff.rb', line 22 def verified? return @verified unless @verified.nil? return @verified = false unless command_types_match? @verified = @matcher.match? end |