Sha256: 649062f37113880b1e5842974288b58f5c767e4c9fddf2565b52d2cb7408fb96

Contents?: true

Size: 1.56 KB

Versions: 38

Compression:

Stored size: 1.56 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 [TrueClass, FalseClass] 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

if RSpec::Expectations::Version::STRING >= '3.0'
  RSpec::Matchers.alias_matcher :a_directory_having_sub_directory, :have_sub_directory
end

Version data entries

38 entries across 38 versions & 3 rubygems

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