Sha256: 907ee1168a6ab2b28aa20fedbe86e6ba2f8d6524b0d2caef3ed8f3af506ca6ed

Contents?: true

Size: 1.23 KB

Versions: 2

Compression:

Stored size: 1.23 KB

Contents

require 'fileutils'

# @!method have_same_file_content_like(file_name)
#   This matchers checks if <file1> has the same content like <file2>
#
#   @param [String] file_name
#     The name of the file which should be compared with the file in the
#     `expect()`-call.
#
#   @return [TrueClass, FalseClass] The result
#
#     false:
#     * if file1 is not equal file2
#     true:
#     * if file1 is equal file2
#
#   @example Use matcher
#
#     RSpec.describe do
#       it { expect(file1).to have_same_file_content_like(file2) }
#       it { expect(files).to include a_file_with_same_content_like(file2) }
#     end
RSpec::Matchers.define :have_same_file_content_like do |expected|
  match do |actual|
    stop_processes!

    next false unless file?(actual) && file?(expected)

    @actual = expand_path(actual)
    @expected = expand_path(expected)

    FileUtils.compare_file(@actual,@expected)
  end

  failure_message do |actual|
    format("expected that file \"%s\" is the same as file \"%s\".", actual, expected)
  end

  failure_message_when_negated do |actual|
    format("expected that file \"%s\" differs from file \"%s\".", actual, expected)
  end
end

RSpec::Matchers.alias_matcher :a_file_with_same_content_like, :have_same_file_content_like

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
aruba-0.8.0.pre2 lib/aruba/matchers/file/have_same_file_content.rb
aruba-0.8.0.pre lib/aruba/matchers/file/have_same_file_content.rb