assert_dirs_equal 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -2
- data/CHANGELOG.md +7 -1
- data/README.md +1 -1
- data/assert_dirs_equal.gemspec +1 -1
- data/lib/assert_dirs_equal/matcher.rb +32 -4
- data/test/cases/glob_filename_matches_exactly_once/expected/%7Bone%2Ctwo%7D.txt +1 -0
- data/test/cases/glob_filename_matches_exactly_once/target/two.txt +1 -0
- data/test/cases/glob_filename_matches_more_than_once/expected/%7Bone%2Ctwo%7D.txt +1 -0
- data/test/cases/glob_filename_matches_more_than_once/target/one.txt +1 -0
- data/test/cases/glob_filename_matches_more_than_once/target/two.txt +1 -0
- data/test/cases/glob_filename_missing_file/expected/%7Bone%2Ctwo%7D.txt +1 -0
- data/test/cases/glob_filename_missing_file/target/.keep +0 -0
- data/test/matcher_test.rb +17 -0
- metadata +17 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 997e5ede3b2a6e68211dc6eccb594b7463ed616a
|
4
|
+
data.tar.gz: da6a2c8807685d0cfb40e01b8bdefa3b8375e27d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 001f3da0d0a268910f316196d90c1ff0dd48eabb0796cac42753ef55166d6f53fc184d7db09d3e9e5a50c62e48c3574943095ac8b00966a5ba9b9d2d36f3b411
|
7
|
+
data.tar.gz: 8031936c26969471a6a6bf80db2dc7dae9bf04eeb45768c370055424faa0d82a9b4ffa9dc78b5699d73cfe290292a8c85060ffe23251b3447cc73ee9338d0fc5
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
data/assert_dirs_equal.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "assert_dirs_equal"
|
3
|
-
spec.version = "0.
|
3
|
+
spec.version = "0.3.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"
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require "cgi"
|
2
|
+
|
1
3
|
# @since 0.1.0
|
2
4
|
module AssertDirsEqual
|
3
5
|
class Diff
|
@@ -23,6 +25,21 @@ module AssertDirsEqual
|
|
23
25
|
@exact_match = options.fetch(:exact_match, true)
|
24
26
|
end
|
25
27
|
|
28
|
+
# Takes each file that exists in `expected` directory and expects to find exactly the same (by name and
|
29
|
+
# by content) file in `target` directory.
|
30
|
+
#
|
31
|
+
# Since 0.3.0 you can use {https://ruby-doc.org/core-2.2.3/Dir.html#method-c-glob glob patterns} in a filename.
|
32
|
+
# This is handy, for example, than you match fingerprinted files and don't want to deal with fingerprinting
|
33
|
+
# algorithm. Pattern should be {https://en.wikipedia.org/wiki/Percent-encoding percent-encoded}. Make sure it is
|
34
|
+
# strict enough to match only one file in `target` directory.
|
35
|
+
#
|
36
|
+
# @example Using percent-encoded glob patterns in filenames (file*.txt)
|
37
|
+
# expected\
|
38
|
+
# file%2A.txt
|
39
|
+
#
|
40
|
+
# target\
|
41
|
+
# file_that_will_be_matched.txt
|
42
|
+
#
|
26
43
|
# @param [String] target path to a directory which contains result of executing a method under test.
|
27
44
|
# @return [true] when `exact_match` is true and `target` mirrors `expected` directory.
|
28
45
|
# @return [true] when `exact_match` is false and `target` contains all files from `expected` directory.
|
@@ -49,8 +66,19 @@ module AssertDirsEqual
|
|
49
66
|
|
50
67
|
private
|
51
68
|
|
69
|
+
def first_with_glob(path)
|
70
|
+
Dir.glob(path).first
|
71
|
+
end
|
72
|
+
|
52
73
|
def assert_exists(path, msg = nil)
|
53
|
-
|
74
|
+
actual_paths = Dir.glob(path)
|
75
|
+
|
76
|
+
case actual_paths.size
|
77
|
+
when 0 then fail_with(msg || "expected #{path.inspect} to exist")
|
78
|
+
when 1 then true
|
79
|
+
else
|
80
|
+
fail_with("found multiple matches for #{path.inspect}, should be just one of the following #{actual_paths.map(&:inspect).join(", ")}")
|
81
|
+
end
|
54
82
|
end
|
55
83
|
|
56
84
|
def assert_directory(directory)
|
@@ -61,7 +89,7 @@ module AssertDirsEqual
|
|
61
89
|
return true if File.directory?(expected) && File.directory?(target)
|
62
90
|
|
63
91
|
expected_content = File.read(expected)
|
64
|
-
target_content = File.read(target)
|
92
|
+
target_content = File.read(first_with_glob(target))
|
65
93
|
|
66
94
|
expected_content = expected_content.strip
|
67
95
|
target_content = target_content.strip
|
@@ -85,7 +113,7 @@ module AssertDirsEqual
|
|
85
113
|
def refute_extra_files_in_target
|
86
114
|
return true unless @exact_match
|
87
115
|
|
88
|
-
expected_files = both_paths_in(@expected, @target).map { |
|
116
|
+
expected_files = both_paths_in(@expected, @target).map { |(_, target_path)| first_with_glob(target_path) }
|
89
117
|
actual_expected_files = Dir.glob(File.join(@target, "**/*"))
|
90
118
|
diff = actual_expected_files - expected_files
|
91
119
|
diff.empty? || fail_with("found unexpected files #{diff.inspect}")
|
@@ -101,7 +129,7 @@ module AssertDirsEqual
|
|
101
129
|
glob = File.join(expected, "**/*")
|
102
130
|
Dir.glob(glob).each do |expected_full_path|
|
103
131
|
path = expected_full_path.sub(expected, "")
|
104
|
-
target_full_path = File.join(target, path)
|
132
|
+
target_full_path = File.join(target, CGI.unescape(path))
|
105
133
|
y << [expected_full_path, target_full_path]
|
106
134
|
end
|
107
135
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
hello
|
@@ -0,0 +1 @@
|
|
1
|
+
hello
|
@@ -0,0 +1 @@
|
|
1
|
+
hello
|
@@ -0,0 +1 @@
|
|
1
|
+
hello
|
@@ -0,0 +1 @@
|
|
1
|
+
hello
|
@@ -0,0 +1 @@
|
|
1
|
+
hello
|
File without changes
|
data/test/matcher_test.rb
CHANGED
@@ -99,6 +99,23 @@ MSG
|
|
99
99
|
matcher.matches?(target_dir)
|
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
|
+
|
103
|
+
def test_glob_filename_matches_exactly_once
|
104
|
+
@case_directory = "test/cases/glob_filename_matches_exactly_once"
|
105
|
+
assert matcher.matches?(target_dir), matcher.failure_message
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_glob_filename_matches_more_than_once
|
109
|
+
@case_directory = "test/cases/glob_filename_matches_more_than_once"
|
110
|
+
refute matcher.matches?(target_dir)
|
111
|
+
assert_equal "found multiple matches for \"#{target_dir}/{one,two}.txt\", should be just one of the following \"#{target_dir}/one.txt\", \"#{target_dir}/two.txt\"", matcher.failure_message
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_glob_filename_missing_file
|
115
|
+
@case_directory = "test/cases/glob_filename_missing_file"
|
116
|
+
refute matcher.matches?(target_dir)
|
117
|
+
assert_equal "expected \"#{target_dir}/{one,two}.txt\" to exist since \"#{expected_dir}/%7Bone%2Ctwo%7D.txt\" exists", matcher.failure_message
|
118
|
+
end
|
102
119
|
end
|
103
120
|
|
104
121
|
class MatcherIncludesTest < MatcherEqTest
|
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.
|
4
|
+
version: 0.3.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:
|
11
|
+
date: 2017-10-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -86,6 +86,13 @@ files:
|
|
86
86
|
- test/cases/extra_file_in_target/target/.keep
|
87
87
|
- test/cases/extra_file_in_target/target/common_file
|
88
88
|
- test/cases/extra_file_in_target/target/file
|
89
|
+
- test/cases/glob_filename_matches_exactly_once/expected/%7Bone%2Ctwo%7D.txt
|
90
|
+
- test/cases/glob_filename_matches_exactly_once/target/two.txt
|
91
|
+
- test/cases/glob_filename_matches_more_than_once/expected/%7Bone%2Ctwo%7D.txt
|
92
|
+
- test/cases/glob_filename_matches_more_than_once/target/one.txt
|
93
|
+
- test/cases/glob_filename_matches_more_than_once/target/two.txt
|
94
|
+
- test/cases/glob_filename_missing_file/expected/%7Bone%2Ctwo%7D.txt
|
95
|
+
- test/cases/glob_filename_missing_file/target/.keep
|
89
96
|
- test/cases/large_different_text_files/expected/file
|
90
97
|
- test/cases/large_different_text_files/target/file
|
91
98
|
- test/cases/missing_expected/.keep
|
@@ -125,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
132
|
version: '0'
|
126
133
|
requirements: []
|
127
134
|
rubyforge_project:
|
128
|
-
rubygems_version: 2.
|
135
|
+
rubygems_version: 2.6.11
|
129
136
|
signing_key:
|
130
137
|
specification_version: 4
|
131
138
|
summary: Test assertion for directories equality by tree and content comparison
|
@@ -145,6 +152,13 @@ test_files:
|
|
145
152
|
- test/cases/extra_file_in_target/target/.keep
|
146
153
|
- test/cases/extra_file_in_target/target/common_file
|
147
154
|
- test/cases/extra_file_in_target/target/file
|
155
|
+
- test/cases/glob_filename_matches_exactly_once/expected/%7Bone%2Ctwo%7D.txt
|
156
|
+
- test/cases/glob_filename_matches_exactly_once/target/two.txt
|
157
|
+
- test/cases/glob_filename_matches_more_than_once/expected/%7Bone%2Ctwo%7D.txt
|
158
|
+
- test/cases/glob_filename_matches_more_than_once/target/one.txt
|
159
|
+
- test/cases/glob_filename_matches_more_than_once/target/two.txt
|
160
|
+
- test/cases/glob_filename_missing_file/expected/%7Bone%2Ctwo%7D.txt
|
161
|
+
- test/cases/glob_filename_missing_file/target/.keep
|
148
162
|
- test/cases/large_different_text_files/expected/file
|
149
163
|
- test/cases/large_different_text_files/target/file
|
150
164
|
- test/cases/missing_expected/.keep
|
@@ -164,4 +178,3 @@ test_files:
|
|
164
178
|
- test/matcher_test.rb
|
165
179
|
- test/minitest_integration_test.rb
|
166
180
|
- test/test_helper.rb
|
167
|
-
has_rdoc:
|