Skip to content

Commit

Permalink
Remove snapshot content from rspec description
Browse files Browse the repository at this point in the history
# 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: levinmr#48
  • Loading branch information
dmorgan-fa committed May 20, 2024
1 parent 8ecbe55 commit a0c1d60
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 2 additions & 0 deletions lib/rspec/snapshot/file_operator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/snapshot/matchers/match_snapshot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
10 changes: 5 additions & 5 deletions spec/rspec/snapshot/matchers/match_snapshot_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a0c1d60

Please sign in to comment.