Sha256: 304d8ceb4fa2b9ea2a86c93755a88cfcd7b84fdf8df9f7fbafec70495cfb71d5

Contents?: true

Size: 1.55 KB

Versions: 5

Compression:

Stored size: 1.55 KB

Contents

require "rspec/expectations/version"

# @!method have_sub_directory(sub_directory)
#   This matchers checks if <directory> has given sub-directory
#
#   @param [Array] sub_directory
#      A list of sub-directory relative to current directory
#
#   @return [Boolean] The result
#
#     false:
#     * if directory does not have sub-directory
#     true:
#     * if directory has sub-directory
#
#   @example Use matcher with single directory
#
#     RSpec.describe do
#       it { expect('dir1.d').to have_sub_directory('subdir.1.d') }
#     end
#
#   @example Use matcher with multiple directories
#
#     RSpec.describe do
#       it { expect('dir1.d').to have_sub_directory(['subdir.1.d', 'subdir.2.d']) }
#       it { expect(directories)
#       .  to include a_directory_with_sub_directory(['subdir.1.d', 'subdir.2.d']) }
#     end
RSpec::Matchers.define :have_sub_directory do |expected|
  match do |actual|
    next false unless directory?(actual)

    @old_actual = actual
    @actual = list(actual)

    @expected = Array(expected).map { |p| File.join(@old_actual, p) }

    (@expected - @actual).empty?
  end

  diffable

  failure_message do |actual|
    format('expected that directory "%s" has the following sub-directories: %s.',
           actual.join(", "),
           expected)
  end

  failure_message_when_negated do |actual|
    format('expected that directory "%s" does not have the following sub-directories: %s.',
           actual.join(", "),
           expected)
  end
end

RSpec::Matchers.alias_matcher :a_directory_having_sub_directory, :have_sub_directory

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
phillipug-foodie-0.1.0 .vendor/ruby/3.0.0/gems/aruba-2.0.0/lib/aruba/matchers/directory/have_sub_directory.rb
aruba-2.0.0 lib/aruba/matchers/directory/have_sub_directory.rb
aruba-1.1.2 lib/aruba/matchers/directory/have_sub_directory.rb
aruba-1.1.1 lib/aruba/matchers/directory/have_sub_directory.rb
aruba-1.1.0 lib/aruba/matchers/directory/have_sub_directory.rb