Skip to content

Commit

Permalink
feat: improve updating snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
mdwagner committed Sep 22, 2023
1 parent d43dd6c commit 01e84bf
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions spec/spec_helper2.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ require "../src/lucky_cli"

include LuckyTemplate::Spec

SPEC_UPDATE_SNAPSHOT = ENV["SPEC_UPDATE_SNAPSHOT"]? == "1"

def generate_snapshot(fixture_name, file = __FILE__, line = __LINE__, &)
generator = yield

actual_path = Path[Dir.current]
expected_path = Path["#{__DIR__}/../fixtures"] / fixture_name / "expected"

# NOTE: Should only be run for initial generation
{% if flag?(:baseline_expected) %}
if SPEC_UPDATE_SNAPSHOT
FileUtils.rm_rf(expected_path)
FileUtils.mkdir_p(expected_path)
generator.render(expected_path)
{% end %}
end

FileUtils.mkdir_p(actual_path)
generator.render(actual_path)
Expand Down

0 comments on commit 01e84bf

Please sign in to comment.