Class: SnapshotTesting::RSpec::MatchSnapshot

Inherits:
Object
  • Object
show all
Defined in:
lib/snapshot_testing/rspec.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(recorder:) ⇒ MatchSnapshot

Returns a new instance of MatchSnapshot.



26
27
28
# File 'lib/snapshot_testing/rspec.rb', line 26

def initialize(recorder:)
  @recorder = recorder
end

Instance Attribute Details

#actualObject (readonly)

Returns the value of attribute actual.



24
25
26
# File 'lib/snapshot_testing/rspec.rb', line 24

def actual
  @actual
end

#expectedObject (readonly)

Returns the value of attribute expected.



24
25
26
# File 'lib/snapshot_testing/rspec.rb', line 24

def expected
  @expected
end

Instance Method Details

#diffable?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/snapshot_testing/rspec.rb', line 42

def diffable?
  true
end

#failure_messageObject



36
37
38
39
40
# File 'lib/snapshot_testing/rspec.rb', line 36

def failure_message
  expected = ::RSpec::Support::ObjectFormatter.format(@expected)
  actual = ::RSpec::Support::ObjectFormatter.format(@actual)
  "\nexpected: #{expected}\n     got: #{actual}\n\n(compared using ==)\n"
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
33
34
# File 'lib/snapshot_testing/rspec.rb', line 30

def matches?(actual)
  @actual = actual
  @expected = @recorder.record(@actual)
  @actual == @expected
end

#supports_block_expectations?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/snapshot_testing/rspec.rb', line 46

def supports_block_expectations?
  false
end