assert_dirs_equal 0.2.0 → 0.3.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: 002b57d9c03d727d23f6ac8059eb6e1de156be63
4
- data.tar.gz: ed8ebb85d512aa507f22f24269f3d2f5cbc90997
3
+ metadata.gz: 997e5ede3b2a6e68211dc6eccb594b7463ed616a
4
+ data.tar.gz: da6a2c8807685d0cfb40e01b8bdefa3b8375e27d
5
5
  SHA512:
6
- metadata.gz: fd82b42b05ce266279c30771d5490bfee1d63e7e113a8bfcbbabd913668010701d474c759f1eef100ab39621c634d64fd737972134e8fa3ee3f82c09d15c7709
7
- data.tar.gz: 44a8ccd5535dcca0f4a537dc259b5a98a3c6d54350da07f00be9c0512278648a06605c8bef278e45aae3813806764b03b9ad109aabb4d78e7024c64a86d61282
6
+ metadata.gz: 001f3da0d0a268910f316196d90c1ff0dd48eabb0796cac42753ef55166d6f53fc184d7db09d3e9e5a50c62e48c3574943095ac8b00966a5ba9b9d2d36f3b411
7
+ data.tar.gz: 8031936c26969471a6a6bf80db2dc7dae9bf04eeb45768c370055424faa0d82a9b4ffa9dc78b5699d73cfe290292a8c85060ffe23251b3447cc73ee9338d0fc5
@@ -1,9 +1,10 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
4
3
  - 2.0.0
5
4
  - 2.1
6
5
  - 2.2
6
+ - 2.3
7
+ - 2.4
7
8
  - jruby-19mode
8
- - rbx-2
9
+ - rbx-3
9
10
  bundler_args: --without doc debug
@@ -1,6 +1,12 @@
1
1
  ## Unreleased
2
2
 
3
- ### 0.2.0
3
+ ## 0.3.0
4
+
5
+ ### Enhancements
6
+
7
+ * Allow to provide glob patterns in file names
8
+
9
+ ## 0.2.0
4
10
 
5
11
  ### Enhancements
6
12
 
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.2.0)
15
+ [Released version](http://rubydoc.info/gems/assert_dirs_equal/0.3.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.2.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
- File.exist?(path) || fail_with(msg || "expected #{path.inspect} to exist")
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 { |pair| pair[1] }
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
@@ -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.2.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: 2016-04-03 00:00:00.000000000 Z
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.4.5.1
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: