From a0c1d60cfd4f969048edd8625cceb056448bc1df Mon Sep 17 00:00:00 2001 From: Dale Morgan Date: Mon, 20 May 2024 10:20:10 +0100 Subject: [PATCH] Remove snapshot content from rspec description # What Provide the snapshot file path rather than the contents of the snapshot in rspec description. The snapshot can be many hundreds/thousands of lines long, and doesn't provide much benefit as the description. - resolves: https://github.com/levinmr/rspec-snapshot/issues/48 --- lib/rspec/snapshot/file_operator.rb | 2 ++ lib/rspec/snapshot/matchers/match_snapshot.rb | 2 +- spec/rspec/snapshot/matchers/match_snapshot_spec.rb | 10 +++++----- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/rspec/snapshot/file_operator.rb b/lib/rspec/snapshot/file_operator.rb index 9cc5f60..014dadd 100644 --- a/lib/rspec/snapshot/file_operator.rb +++ b/lib/rspec/snapshot/file_operator.rb @@ -6,6 +6,8 @@ module RSpec module Snapshot # Handles File IO for snapshots class FileOperator + attr_reader :snapshot_path + # Initializes the class instance, and creates the snapshot directory for # the current test if needed. # diff --git a/lib/rspec/snapshot/matchers/match_snapshot.rb b/lib/rspec/snapshot/matchers/match_snapshot.rb index 70bd309..56e1e47 100644 --- a/lib/rspec/snapshot/matchers/match_snapshot.rb +++ b/lib/rspec/snapshot/matchers/match_snapshot.rb @@ -48,7 +48,7 @@ def matches?(actual) end def description - "to match a snapshot containing: \"#{@expected}\"" + "to match a snapshot: '#{@file_operator.snapshot_path}'" end def diffable? diff --git a/spec/rspec/snapshot/matchers/match_snapshot_spec.rb b/spec/rspec/snapshot/matchers/match_snapshot_spec.rb index 1b65681..1994296 100644 --- a/spec/rspec/snapshot/matchers/match_snapshot_spec.rb +++ b/spec/rspec/snapshot/matchers/match_snapshot_spec.rb @@ -79,17 +79,17 @@ end describe '.description' do - subject { described_class.new(nil, nil) } + subject { described_class.new(nil, file_operator) } - let(:expected) { 'snapshot value' } + let(:snapshot_path) { 'path/to/snapshot.snap' } before do - subject.instance_variable_set(:@expected, expected) + allow(file_operator).to receive(:snapshot_path).and_return(snapshot_path) end - it 'returns a description of the expected value' do + it 'returns a description which includes the path to the snapshot' do expect(subject.description).to( - eq("to match a snapshot containing: \"#{expected}\"") + eq("to match a snapshot: '#{snapshot_path}'") ) end end