Module: Capybara::Screenshot::Diff::Vcs

Included in:
TestMethods
Defined in:
lib/capybara/screenshot/diff/vcs.rb

Constant Summary collapse

SILENCE_ERRORS =
Os::ON_WINDOWS ? '2>nul' : '2>/dev/null'

Instance Method Summary collapse

Instance Method Details

#checkout_vcs(name, comparison) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/capybara/screenshot/diff/vcs.rb', line 16

def checkout_vcs(name, comparison)
  svn_file_name = "#{Capybara::Screenshot.screenshot_area_abs}/.svn/text-base/#{name}.png.svn-base"
  if File.exist?(svn_file_name)
    committed_file_name = svn_file_name
    FileUtils.cp committed_file_name, comparison.old_file_name
  else
    svn_info = `svn info #{comparison.new_file_name} #{SILENCE_ERRORS}`
    if svn_info.present?
      wc_root = svn_info.slice(/(?<=Working Copy Root Path: ).*$/)
      checksum = svn_info.slice(/(?<=Checksum: ).*$/)
      if checksum
        committed_file_name = "#{wc_root}/.svn/pristine/#{checksum[0..1]}/#{checksum}.svn-base"
        FileUtils.cp committed_file_name, comparison.old_file_name
      end
    else
      restore_git_revision(name, comparison.old_file_name)
    end
  end
end

#restore_git_revision(name, target_file_name) ⇒ Object



10
11
12
13
14
# File 'lib/capybara/screenshot/diff/vcs.rb', line 10

def restore_git_revision(name, target_file_name)
  redirect_target = "#{target_file_name} #{SILENCE_ERRORS}"
  `git show HEAD~0:./#{Capybara::Screenshot.screenshot_area}/#{name}.png > #{redirect_target}`
  FileUtils.rm_f(target_file_name) unless $CHILD_STATUS == 0
end