module AssertMatchesSnapshot::Assertion

Public Instance Methods

assert_matches_snapshot(key) click to toggle source
# File lib/assert_matches_snapshot/assertion.rb, line 5
def assert_matches_snapshot(key)
  FileUtils.mkpath(snapshot_file_path)

  full_path = snapshot_file_full_path(key)
  if File.exists?(full_path) && !OverwriteSnapshots.active?
    assert_equal response.body, IO.read(full_path)
  else
    File.open(full_path, 'w') do |snapshot_file|
      snapshot_file.write(response.body)
      snapshot_file.flush
    end
  end
end

Private Instance Methods

snapshot_file_full_path(key) click to toggle source
# File lib/assert_matches_snapshot/assertion.rb, line 21
def snapshot_file_full_path(key)
  File.join(File.expand_path(Dir.pwd), snapshot_file_path, snapshot_file_name(key))
end
snapshot_file_name(key) click to toggle source
# File lib/assert_matches_snapshot/assertion.rb, line 29
def snapshot_file_name(key)
  "#{@controller.controller_name}_#{@controller.action_name}_#{key}".downcase.gsub(/\W/, '_') + ".snapshot.html"
end
snapshot_file_path() click to toggle source
# File lib/assert_matches_snapshot/assertion.rb, line 25
def snapshot_file_path
  'test/snapshots'
end