Sha256: 718054c6271650e9b72687860519a4638a374a802ab6b0550368652d53752948

Contents?: true

Size: 1.98 KB

Versions: 2

Compression:

Stored size: 1.98 KB

Contents

require "minitest"
require "assert_dirs_equal/matcher"

module AssertDirsEqual
  class Diff
    extend Minitest::Assertions

    def self.perform(expected, actual)
      diff(expected, actual)
    end
  end
end

class Minitest::Test
  # Fails if `target` lacks some files, or has extra files, or any file in the directory differs
  # from according content in `expected`.
  #
  # @param [String] expected path to a directory which contains expected structure and content.
  # @param [String] target path to a directory which contains result of executing a method under test.
  # @raise [Minitest::Assertion]
  # @since 0.1.0
  def assert_dirs_equal(expected, target)
    matcher = AssertDirsEqual::Matcher.new(expected)
    assert matcher.matches?(target), matcher.failure_message
  end

  # Fails if `target` has exactly the same file tree structure and content.
  #
  # @param (see #assert_dirs_equal)
  # @raise [Minitest::Assertion]
  # @since 0.1.0
  def refute_dirs_equal(expected, target)
    matcher = AssertDirsEqual::Matcher.new(expected)
    refute matcher.matches?(target), matcher.failure_message_when_negated
  end

  # Fails if `target` lacks some files, or any file in the directory differs from according content
  # in `expected`. Should be read as 'Content from `expected` is expected to be "included" in `target`'.
  # @note Extra files in `target` are ignored.
  #
  # @param (see #assert_dirs_equal)
  # @raise [Minitest::Assertion]
  # @since 0.2.0
  def assert_dir_included(expected, target)
    matcher = AssertDirsEqual::Matcher.new(expected, exact_match: false)
    assert matcher.matches?(target), matcher.failure_message
  end

  # Fails if `target` includes the same files from `expected`.
  # @note Extra files in `target` are ignored.
  #
  # @param (see #assert_dirs_equal)
  # @since 0.2.0
  def refute_dir_included(expected, target)
    matcher = AssertDirsEqual::Matcher.new(expected, exact_match: false)
    refute matcher.matches?(target), matcher.failure_message_when_negated
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
assert_dirs_equal-0.3.0 lib/minitest/assert_dirs_equal.rb
assert_dirs_equal-0.2.0 lib/minitest/assert_dirs_equal.rb