Sha256: 64b8102ad4c0d83a1a3bef27f51df3a59261fb069b5fe89172273ca359bf6ceb

Contents?: true

Size: 811 Bytes

Versions: 28

Compression:

Stored size: 811 Bytes

Contents

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

  match do |actual_file_path|
    if File.exist?(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.14.0 spec/support/have_same_content_of.rb
br_danfe-0.13.3 spec/support/have_same_content_of.rb
br_danfe-0.13.2 spec/support/have_same_content_of.rb
br_danfe-0.13.1 spec/support/have_same_content_of.rb
br_danfe-0.13.0 spec/support/have_same_content_of.rb
br_danfe-0.12.1 spec/support/have_same_content_of.rb
br_danfe-0.12.0 spec/support/have_same_content_of.rb
br_danfe-0.11.2 spec/support/have_same_content_of.rb