Sha256: f2337687074d099e5552553284f13e5fa440f50fe9092af109ae9200fbee6585

Contents?: true

Size: 1.23 KB

Versions: 34

Compression:

Stored size: 1.23 KB

Contents

require 'rspec/expectations/version'

# @!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_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

if RSpec::Expectations::Version::STRING >= '3.0'
  RSpec::Matchers.alias_matcher :a_file_of_size, :have_file_size
end

Version data entries

34 entries across 34 versions & 3 rubygems

Version Path
aruba-0.14.14 lib/aruba/matchers/file/have_file_size.rb
aruba-0.14.13 lib/aruba/matchers/file/have_file_size.rb
honeybadger-4.5.3 vendor/bundle/ruby/2.6.0/gems/aruba-0.14.12/lib/aruba/matchers/file/have_file_size.rb
aruba-0.14.12 lib/aruba/matchers/file/have_file_size.rb
aruba-0.14.11 lib/aruba/matchers/file/have_file_size.rb
aruba-0.14.10 lib/aruba/matchers/file/have_file_size.rb
aruba-0.14.9 lib/aruba/matchers/file/have_file_size.rb
aruba-0.14.8 lib/aruba/matchers/file/have_file_size.rb
aruba-0.14.7 lib/aruba/matchers/file/have_file_size.rb
aruba-0.14.6 lib/aruba/matchers/file/have_file_size.rb
aruba-0.14.5 lib/aruba/matchers/file/have_file_size.rb
aruba-0.14.4 lib/aruba/matchers/file/have_file_size.rb
aruba-0.14.3 lib/aruba/matchers/file/have_file_size.rb
aruba-1.0.0.pre.alpha.2 lib/aruba/matchers/file/have_file_size.rb
aruba-1.0.0.pre.alpha.1 lib/aruba/matchers/file/have_file_size.rb
aruba-win-fix-0.14.2 lib/aruba/matchers/file/have_file_size.rb
aruba-0.14.2 lib/aruba/matchers/file/have_file_size.rb
aruba-0.14.1 lib/aruba/matchers/file/have_file_size.rb
aruba-0.14.0 lib/aruba/matchers/file/have_file_size.rb
aruba-0.13.0 lib/aruba/matchers/file/have_file_size.rb