Sha256: 3ad306b1e724368d4f066020303f0c06a04dae644c5255552849124dde12b657

Contents?: true

Size: 812 Bytes

Versions: 28

Compression:

Stored size: 812 Bytes

Contents

RSpec::Matchers.define(:have_same_content_of) do |file: nil|
  expected_file_path = file

  match do |actual_file_path|
    if File.exists?(actual_file_path)
      expect(md5_hash(actual_file_path)).to eq(md5_hash(expected_file_path))
    else
      create_when_missing(expected_file_path, actual_file_path)
    end
  end

  def md5_hash(file_path)
    Digest::MD5.hexdigest(File.read(file_path))
  end

  def create_when_missing(expected_file_path, actual_file_path)
    puts "+----------------------------------------------------"
    puts "|"
    puts "| The file bellow doesn't exists and will be created:"
    puts "|"
    puts "| #{actual_file_path}"
    puts "|"
    puts "+----------------------------------------------------"

    FileUtils.cp(expected_file_path, actual_file_path)

    false
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
br_danfe-0.11.1 spec/support/have_same_content_of.rb
br_danfe-0.11.0 spec/support/have_same_content_of.rb
br_danfe-0.10.1 spec/support/have_same_content_of.rb
br_danfe-0.10.0 spec/support/have_same_content_of.rb
br_danfe-0.8.0 spec/support/have_same_content_of.rb
br_danfe-0.7.7 spec/support/have_same_content_of.rb
br_danfe-0.7.6 spec/support/have_same_content_of.rb
br_danfe-0.7.5 spec/support/have_same_content_of.rb
br_danfe-0.7.4 spec/support/have_same_content_of.rb
br_danfe-0.7.3 spec/support/have_same_content_of.rb
br_danfe-0.7.2 spec/support/have_same_content_of.rb
br_danfe-0.7.1 spec/support/have_same_content_of.rb
br_danfe-0.7.0 spec/support/have_same_content_of.rb
br_danfe-0.6.1 spec/support/have_same_content_of.rb
br_danfe-0.6.0 spec/support/have_same_content_of.rb
br_danfe-0.5.2 spec/support/have_same_content_of.rb
br_danfe-0.5.1 spec/support/have_same_content_of.rb
br_danfe-0.5.0 spec/support/have_same_content_of.rb
br_danfe-0.4.3 spec/support/have_same_content_of.rb
br_danfe-0.4.2 spec/support/have_same_content_of.rb