Sha256: 02124c3bfda7b64eef53a83986925259492bbc97929ffbd2dfa83b0936631d62

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

# @!method have_file_size(size)
#   This matchers checks if path has file size
#
#   @param [Fixnum] size
#     The size to check
#
#   @return [TrueClass, FalseClass] 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_processes!

    next false unless file?(actual)

    @old_actual = actual
    @actual = File.size(expand_path(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

2 entries across 2 versions & 1 rubygems

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