assert_dirs_equal 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aa4cdc7043d5798e78745e4a6fa8e03659516168
4
- data.tar.gz: 54334a10d86c433bafa573757102dbd0a915a906
3
+ metadata.gz: 002b57d9c03d727d23f6ac8059eb6e1de156be63
4
+ data.tar.gz: ed8ebb85d512aa507f22f24269f3d2f5cbc90997
5
5
  SHA512:
6
- metadata.gz: b61f753c46796ed63928ee2f0ab1fe06b1ed0be71f6f6cb6cb180d0e31b9eb8667d993131070938833b247b71d3ed77b31096a14d3dc9d0a2fda6eb2acc3dbaf
7
- data.tar.gz: 606d3e449e37a2050a84834363513cb6dfdb576a8e9c02ac73574b800b460136f1bb02b6bdf5c6a4d455ca4a53058645485708100c7e7fc6dc3a894c8f6ecf10
6
+ metadata.gz: fd82b42b05ce266279c30771d5490bfee1d63e7e113a8bfcbbabd913668010701d474c759f1eef100ab39621c634d64fd737972134e8fa3ee3f82c09d15c7709
7
+ data.tar.gz: 44a8ccd5535dcca0f4a537dc259b5a98a3c6d54350da07f00be9c0512278648a06605c8bef278e45aae3813806764b03b9ad109aabb4d78e7024c64a86d61282
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  ## Unreleased
2
2
 
3
+ ### 0.2.0
4
+
5
+ ### Enhancements
6
+
7
+ * Allow to compare dirs without exact match (i.e. there can be other files and directories inside
8
+ `target_dir` that the matcher won't care about)
9
+
3
10
  ## 0.1.1
4
11
 
5
12
  ### Bug fixes
data/README.md CHANGED
@@ -12,7 +12,7 @@ Production ready.
12
12
 
13
13
  ## Documentation
14
14
 
15
- [Released version](http://rubydoc.info/gems/assert_dirs_equal/0.1.1)
15
+ [Released version](http://rubydoc.info/gems/assert_dirs_equal/0.2.0)
16
16
 
17
17
  ## Why
18
18
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "assert_dirs_equal"
3
- spec.version = "0.1.1"
3
+ spec.version = "0.2.0"
4
4
  spec.authors = ["Andrii Malyshko"]
5
5
  spec.email = ["mail@nashbridges.me"]
6
6
  spec.description = "Test assertion for directories equality by tree and content comparison"
@@ -14,12 +14,21 @@ module AssertDirsEqual
14
14
  # @return [String]
15
15
  attr_reader :failure_message
16
16
 
17
- def initialize(expected)
17
+ # @param [String] expected path to a directory which contains expected structure and content.
18
+ # @param [Hash] options
19
+ # @option options [Boolean] exact_match (true) specifies whether `expected` should mirror `target`,
20
+ # or just be a subset of it.
21
+ def initialize(expected, options = {})
18
22
  @expected = expected
23
+ @exact_match = options.fetch(:exact_match, true)
19
24
  end
20
25
 
21
- # @return [true] if `target` mirrors subdirectory of `expected` directory.
22
- # @return [false] if `target` lacks some files, or has extra files, or any file in subdirectory differs from according file content.
26
+ # @param [String] target path to a directory which contains result of executing a method under test.
27
+ # @return [true] when `exact_match` is true and `target` mirrors `expected` directory.
28
+ # @return [true] when `exact_match` is false and `target` contains all files from `expected` directory.
29
+ # Extra files in `target` does not affect the result.
30
+ # @return [false] if `target` lacks some files, or has extra files (when `exact_match` is true), or any
31
+ # file in subdirectory differs from according file content.
23
32
  def matches?(target)
24
33
  @target = target
25
34
  assert_exists(@expected) && assert_exists(@target) &&
@@ -28,9 +37,14 @@ module AssertDirsEqual
28
37
  refute_extra_files_in_target
29
38
  end
30
39
 
40
+ # @!attribute [r]
31
41
  # @return [String]
32
42
  def failure_message_when_negated
33
- "expected #{@target.inspect} to not be equal to #{@expected.inspect}, but they are equal"
43
+ if @exact_match
44
+ "expected #{@target.inspect} to not be equal to #{@expected.inspect}, but they are equal"
45
+ else
46
+ "expected files from #{@target.inspect} to not be present in #{@expected.inspect}, but they are"
47
+ end
34
48
  end
35
49
 
36
50
  private
@@ -69,6 +83,8 @@ module AssertDirsEqual
69
83
  end
70
84
 
71
85
  def refute_extra_files_in_target
86
+ return true unless @exact_match
87
+
72
88
  expected_files = both_paths_in(@expected, @target).map { |pair| pair[1] }
73
89
  actual_expected_files = Dir.glob(File.join(@target, "**/*"))
74
90
  diff = actual_expected_files - expected_files
@@ -12,13 +12,47 @@ module AssertDirsEqual
12
12
  end
13
13
 
14
14
  class Minitest::Test
15
+ # Fails if `target` lacks some files, or has extra files, or any file in the directory differs
16
+ # from according content in `expected`.
17
+ #
18
+ # @param [String] expected path to a directory which contains expected structure and content.
19
+ # @param [String] target path to a directory which contains result of executing a method under test.
20
+ # @raise [Minitest::Assertion]
21
+ # @since 0.1.0
15
22
  def assert_dirs_equal(expected, target)
16
23
  matcher = AssertDirsEqual::Matcher.new(expected)
17
24
  assert matcher.matches?(target), matcher.failure_message
18
25
  end
19
26
 
27
+ # Fails if `target` has exactly the same file tree structure and content.
28
+ #
29
+ # @param (see #assert_dirs_equal)
30
+ # @raise [Minitest::Assertion]
31
+ # @since 0.1.0
20
32
  def refute_dirs_equal(expected, target)
21
33
  matcher = AssertDirsEqual::Matcher.new(expected)
22
34
  refute matcher.matches?(target), matcher.failure_message_when_negated
23
35
  end
36
+
37
+ # Fails if `target` lacks some files, or any file in the directory differs from according content
38
+ # in `expected`. Should be read as 'Content from `expected` is expected to be "included" in `target`'.
39
+ # @note Extra files in `target` are ignored.
40
+ #
41
+ # @param (see #assert_dirs_equal)
42
+ # @raise [Minitest::Assertion]
43
+ # @since 0.2.0
44
+ def assert_dir_included(expected, target)
45
+ matcher = AssertDirsEqual::Matcher.new(expected, exact_match: false)
46
+ assert matcher.matches?(target), matcher.failure_message
47
+ end
48
+
49
+ # Fails if `target` includes the same files from `expected`.
50
+ # @note Extra files in `target` are ignored.
51
+ #
52
+ # @param (see #assert_dirs_equal)
53
+ # @since 0.2.0
54
+ def refute_dir_included(expected, target)
55
+ matcher = AssertDirsEqual::Matcher.new(expected, exact_match: false)
56
+ refute matcher.matches?(target), matcher.failure_message_when_negated
57
+ end
24
58
  end
data/test/matcher_test.rb CHANGED
@@ -2,7 +2,7 @@ require "test_helper"
2
2
  require "assert_dirs_equal/matcher"
3
3
 
4
4
  module AssertDirsEqual
5
- class MatcherTest < Minitest::Test
5
+ class MatcherEqTest < Minitest::Test
6
6
  def matcher
7
7
  @matcher ||= Matcher.new(expected_dir)
8
8
  end
@@ -100,4 +100,21 @@ MSG
100
100
  assert_equal "expected \"#{target_dir}\" to not be equal to \"#{expected_dir}\", but they are equal", matcher.failure_message_when_negated
101
101
  end
102
102
  end
103
+
104
+ class MatcherIncludesTest < MatcherEqTest
105
+ def matcher
106
+ @matcher ||= Matcher.new(expected_dir, exact_match: false)
107
+ end
108
+
109
+ def test_extra_file_in_target
110
+ @case_directory = "test/cases/extra_file_in_target"
111
+ assert matcher.matches?(target_dir), matcher.failure_message
112
+ end
113
+
114
+ def test_failure_message_negated
115
+ @case_directory = "test/cases/empty_dirs_are_equal"
116
+ matcher.matches?(target_dir)
117
+ assert_equal "expected files from \"#{target_dir}\" to not be present in \"#{expected_dir}\", but they are", matcher.failure_message_when_negated
118
+ end
119
+ end
103
120
  end
@@ -3,12 +3,12 @@ require "minitest/assert_dirs_equal"
3
3
 
4
4
  module AssertDirsEqual
5
5
  class MinitestIntegrationTest < Minitest::Test
6
- def test_successful_assert
6
+ def test_successful_assert_dirs_equal
7
7
  @case_directory = "test/cases/empty_files_are_equal"
8
8
  assert_dirs_equal expected_dir, target_dir
9
9
  end
10
10
 
11
- def test_failed_assert
11
+ def test_failed_assert_dirs_equal
12
12
  @case_directory = "test/cases/missing_expected"
13
13
 
14
14
  error = assert_raises(Minitest::Assertion) do
@@ -18,12 +18,12 @@ module AssertDirsEqual
18
18
  assert_equal "expected \"#{expected_dir}\" to exist", error.message
19
19
  end
20
20
 
21
- def test_successful_refute
21
+ def test_successful_refute_dirs_equal
22
22
  @case_directory = "test/cases/missing_expected"
23
23
  refute_dirs_equal expected_dir, target_dir
24
24
  end
25
25
 
26
- def test_failed_refute
26
+ def test_failed_refute_dirs_equal
27
27
  @case_directory = "test/cases/empty_files_are_equal"
28
28
 
29
29
  error = assert_raises(Minitest::Assertion) do
@@ -33,6 +33,36 @@ module AssertDirsEqual
33
33
  assert_equal "expected \"#{target_dir}\" to not be equal to \"#{expected_dir}\", but they are equal", error.message
34
34
  end
35
35
 
36
+ def test_successful_assert_dir_included
37
+ @case_directory = "test/cases/extra_file_in_target"
38
+ assert_dir_included expected_dir, target_dir
39
+ end
40
+
41
+ def test_failed_assert_dir_included
42
+ @case_directory = "test/cases/missing_expected"
43
+
44
+ error = assert_raises(Minitest::Assertion) do
45
+ assert_dir_included expected_dir, target_dir
46
+ end
47
+
48
+ assert_equal "expected \"#{expected_dir}\" to exist", error.message
49
+ end
50
+
51
+ def test_successful_refute_dir_included
52
+ @case_directory = "test/cases/missing_expected"
53
+ refute_dir_included expected_dir, target_dir
54
+ end
55
+
56
+ def test_failed_refute_dir_included
57
+ @case_directory = "test/cases/empty_files_are_equal"
58
+
59
+ error = assert_raises(Minitest::Assertion) do
60
+ refute_dir_included expected_dir, target_dir
61
+ end
62
+
63
+ assert_equal "expected files from \"#{target_dir}\" to not be present in \"#{expected_dir}\", but they are", error.message
64
+ end
65
+
36
66
  def test_minitest_powered_diff
37
67
  @case_directory = "test/cases/large_different_text_files"
38
68
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: assert_dirs_equal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrii Malyshko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-02 00:00:00.000000000 Z
11
+ date: 2016-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -82,7 +82,9 @@ files:
82
82
  - test/cases/expected_is_not_a_dir/expected
83
83
  - test/cases/expected_is_not_a_dir/target/.keep
84
84
  - test/cases/extra_file_in_target/expected/.keep
85
+ - test/cases/extra_file_in_target/expected/common_file
85
86
  - test/cases/extra_file_in_target/target/.keep
87
+ - test/cases/extra_file_in_target/target/common_file
86
88
  - test/cases/extra_file_in_target/target/file
87
89
  - test/cases/large_different_text_files/expected/file
88
90
  - test/cases/large_different_text_files/target/file
@@ -139,7 +141,9 @@ test_files:
139
141
  - test/cases/expected_is_not_a_dir/expected
140
142
  - test/cases/expected_is_not_a_dir/target/.keep
141
143
  - test/cases/extra_file_in_target/expected/.keep
144
+ - test/cases/extra_file_in_target/expected/common_file
142
145
  - test/cases/extra_file_in_target/target/.keep
146
+ - test/cases/extra_file_in_target/target/common_file
143
147
  - test/cases/extra_file_in_target/target/file
144
148
  - test/cases/large_different_text_files/expected/file
145
149
  - test/cases/large_different_text_files/target/file