Sha256: 6bc0e18ef35e30f7e58875b33d0f74fe94ccb8ef9c4c53beacb597d8d67e97e2

Contents?: true

Size: 1.14 KB

Versions: 5

Compression:

Stored size: 1.14 KB

Contents

# @!method have_file_size(size)
#   This matchers checks if path has file size
#
#   @param [Fixnum] size
#     The size to check
#
#   @return [Boolean] The result
#
#     false:
#     * if path does not have size
#     true:
#     * if path has size
#
#   @example Use matcher
#
#     RSpec.describe do
#       it { expect('file.txt').to have_file_size(0) }
#       it { expect(%w(file.txt file2.txt)).to all have_file_size(0) }
#       it { expect(%w(file.txt file2.txt)).to include a_file_of_size(0) }
#     end
RSpec::Matchers.define :have_file_size do |expected|
  match do |actual|
    stop_all_commands

    next false unless file?(actual)

    @old_actual = actual
    @actual = file_size(actual)
    @expected = expected.to_i

    values_match?(@expected, @actual)
  end

  failure_message do |_actual|
    format('expected that file "%s" has size "%s", but has "%s"',
           @old_actual, @actual, @expected)
  end

  failure_message_when_negated do |_actual|
    format('expected that file "%s" does not have size "%s", but has "%s"',
           @old_actual, @actual, @expected)
  end
end

RSpec::Matchers.alias_matcher :a_file_of_size, :have_file_size

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/aruba-2.2.0/lib/aruba/matchers/file/have_file_size.rb
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/aruba-2.2.0/lib/aruba/matchers/file/have_file_size.rb
aruba-2.2.0 lib/aruba/matchers/file/have_file_size.rb
aruba-2.1.0 lib/aruba/matchers/file/have_file_size.rb
aruba-2.0.1 lib/aruba/matchers/file/have_file_size.rb