Skip to content

Commit

Permalink
fail the spec whenever we write a snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelglass committed Dec 8, 2022
1 parent 14004e4 commit 88caa84
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
46 changes: 30 additions & 16 deletions spec/rspec/snapshot/matchers/match_snapshot_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ def dump(object)
expect(file).to have_received(:close).twice
end

it 'returns true' do
expect(@actual).to be(true)
it 'returns false' do
expect(@actual).to be(false)
end
end

Expand Down Expand Up @@ -285,8 +285,8 @@ def dump(object)
expect(file).to have_received(:close).twice
end

it 'returns true' do
expect(@actual).to be(true)
it 'returns false' do
expect(@actual).to be(false)
end
end
end
Expand Down Expand Up @@ -335,8 +335,8 @@ def dump(object)
expect(file).to have_received(:close).twice
end

it 'returns true' do
expect(@actual).to be(true)
it 'returns false' do
expect(@actual).to be(false)
end
end

Expand Down Expand Up @@ -383,8 +383,8 @@ def dump(object)
expect(file).to have_received(:close).twice
end

it 'returns true' do
expect(@actual).to be(true)
it 'returns false' do
expect(@actual).to be(false)
end
end
end
Expand Down Expand Up @@ -609,8 +609,8 @@ def dump(object)
expect(file).to have_received(:close).twice
end

it 'returns true' do
expect(@actual).to be(true)
it 'returns false' do
expect(@actual).to be(false)
end
end

Expand Down Expand Up @@ -657,8 +657,8 @@ def dump(object)
expect(file).to have_received(:close).twice
end

it 'returns true' do
expect(@actual).to be(true)
it 'returns false' do
expect(@actual).to be(false)
end
end
end
Expand Down Expand Up @@ -700,10 +700,24 @@ def dump(object)
subject.instance_variable_set(:@actual, actual)
end

it 'returns a failure message including the actual and expected' do
expect(subject.failure_message).to(
eq("\nexpected: #{expected}\n got: #{actual}\n")
)
context 'when should_write? is true' do
it 'returns a failure message including the actual and expected' do
expect(subject.failure_message).to(
eq("failing because we wrote a snapshot")
)
end
end

context 'when should_write? is false' do
before {
allow(subject).to receive(:should_write?).and_return(false)
}

it 'returns a failure message including the actual and expected' do
expect(subject.failure_message).to(
eq("\nexpected: #{expected}\n got: #{actual}\n")
)
end
end
end

Expand Down
6 changes: 5 additions & 1 deletion spec/rspec/snapshot/matchers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,9 @@ def dump(object)
file.write(original_snapshot_value)
file.close
# rubocop:disable RSpec/ExpectInHook
expect(updated_snapshot_value).to match_snapshot(snapshot_name)
expect {
expect(updated_snapshot_value).to match_snapshot(snapshot_name)
}.to raise_error
# rubocop:enable RSpec/ExpectInHook
file = File.new(snapshot_path)
@actual = file.read
Expand All @@ -295,7 +297,9 @@ def dump(object)
before do
File.unlink(snapshot_path) if File.exist?(snapshot_path)
# rubocop:disable RSpec/ExpectInHook
expect {
expect(snapshot_value).to match_snapshot(snapshot_name)
}.to raise_error
# rubocop:enable RSpec/ExpectInHook
file = File.new(snapshot_path)
@actual = file.read
Expand Down

0 comments on commit 88caa84

Please sign in to comment.