Sha256: 9495e4dbe12e4e1872260b7f7d46b6a4b019e594e735998adfadbd67a48d9f15

Contents?: true

Size: 1.32 KB

Versions: 4

Compression:

Stored size: 1.32 KB

Contents

require 'rspec/expectations/version'

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

if RSpec::Expectations::Version::STRING >= '3.0'
  RSpec::Matchers.alias_matcher :a_file_with_same_content_like, :have_same_file_content_like
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
aruba-0.9.0.pre lib/aruba/matchers/file/have_same_file_content.rb
aruba-0.8.1 lib/aruba/matchers/file/have_same_file_content.rb
aruba-0.8.0 lib/aruba/matchers/file/have_same_file_content.rb
aruba-0.8.0.pre3 lib/aruba/matchers/file/have_same_file_content.rb