Class: Backspin::CommandDiff
- Inherits:
-
Object
- Object
- Backspin::CommandDiff
- Defined in:
- lib/backspin/command_diff.rb
Overview
Represents the difference between a recorded command and actual execution Handles verification and diff generation for a single command
Instance Attribute Summary collapse
-
#actual_command ⇒ Object
readonly
Returns the value of attribute actual_command.
-
#matcher ⇒ Object
readonly
Returns the value of attribute matcher.
-
#recorded_command ⇒ Object
readonly
Returns the value of attribute recorded_command.
Instance Method Summary collapse
-
#diff ⇒ String?
Human-readable diff if not verified.
-
#initialize(recorded_command:, actual_command:, matcher: nil) ⇒ CommandDiff
constructor
A new instance of CommandDiff.
-
#summary ⇒ String
Single line summary for error messages.
-
#verified? ⇒ Boolean
True if the command output matches.
Constructor Details
#initialize(recorded_command:, actual_command:, matcher: nil) ⇒ CommandDiff
Returns a new instance of CommandDiff.
9 10 11 12 13 14 15 16 17 |
# File 'lib/backspin/command_diff.rb', line 9 def initialize(recorded_command:, actual_command:, matcher: nil) @recorded_command = recorded_command @actual_command = actual_command @matcher = Matcher.new( config: matcher, recorded_command: recorded_command, actual_command: actual_command ) end |
Instance Attribute Details
#actual_command ⇒ Object (readonly)
Returns the value of attribute actual_command.
7 8 9 |
# File 'lib/backspin/command_diff.rb', line 7 def actual_command @actual_command end |
#matcher ⇒ Object (readonly)
Returns the value of attribute matcher.
7 8 9 |
# File 'lib/backspin/command_diff.rb', line 7 def matcher @matcher end |
#recorded_command ⇒ Object (readonly)
Returns the value of attribute recorded_command.
7 8 9 |
# File 'lib/backspin/command_diff.rb', line 7 def recorded_command @recorded_command end |
Instance Method Details
#diff ⇒ String?
Returns Human-readable diff if not verified.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/backspin/command_diff.rb', line 27 def diff return nil if verified? parts = [] unless method_classes_match? parts << "Command type mismatch: expected #{recorded_command.method_class.name}, got #{actual_command.method_class.name}" end parts << stdout_diff if recorded_command.stdout != actual_command.stdout parts << stderr_diff if recorded_command.stderr != actual_command.stderr if recorded_command.status != actual_command.status parts << "Exit status: expected #{recorded_command.status}, got #{actual_command.status}" end parts.join("\n\n") end |
#summary ⇒ String
Returns Single line summary for error messages.
48 49 50 51 52 53 54 |
# File 'lib/backspin/command_diff.rb', line 48 def summary if verified? "✓ Command verified" else "✗ Command failed: #{failure_reason}" end end |
#verified? ⇒ Boolean
Returns true if the command output matches.
20 21 22 23 24 |
# File 'lib/backspin/command_diff.rb', line 20 def verified? return false unless method_classes_match? @matcher.match? end |