Class: Backspin::CommandDiff

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_commandObject (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

#matcherObject (readonly)

Returns the value of attribute matcher.



7
8
9
# File 'lib/backspin/command_diff.rb', line 7

def matcher
  @matcher
end

#recorded_commandObject (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

#diffString?

Returns Human-readable diff if not verified.

Returns:

  • (String, nil)

    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

#summaryString

Returns Single line summary for error messages.

Returns:

  • (String)

    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.

Returns:

  • (Boolean)

    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