Class: Backspin::CommandDiff

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

Instance Method Summary collapse

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

#actualObject (readonly)

Returns the value of attribute actual.



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

def actual
  @actual
end

#expectedObject (readonly)

Returns the value of attribute expected.



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

def expected
  @expected
end

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

#diffString?

Returns Human-readable diff if not verified.

Returns:

  • (String, nil)

    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

#summaryString

Returns Single line summary for error messages.

Returns:

  • (String)

    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.

Returns:

  • (Boolean)

    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