minitest-filesystem 0.0.1
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 +7 -0
- data/.gitignore +17 -0
- data/.ruby-version +1 -0
- data/.travis.yml +13 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +82 -0
- data/Rakefile +12 -0
- data/lib/minitest/filesystem/matcher.rb +95 -0
- data/lib/minitest/filesystem/version.rb +5 -0
- data/lib/minitest/filesystem.rb +9 -0
- data/minitest-filesystem.gemspec +25 -0
- data/test/filesystem_test.rb +96 -0
- data/test/test_helper.rb +4 -0
- metadata +102 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b364d783dce84d3efbc20abb86664ed9b236b416
|
4
|
+
data.tar.gz: 094022ba019ef0e6035cb831244e63a389317b8f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9334f162c83d5baf45d0f00ca8798e2933fca944ac6eee2fb41098062e7a3d1d45dacb76cec9d8d6800062f58b35c45a462df4b37c34d91dd9b81cc310c24fc2
|
7
|
+
data.tar.gz: 5b4bd753d6241f2104ce3c3e8b876190130274dc81c66c8baecf644c48b0711dddd903d4c9ccf249c62fa8c0a475cc33521a6ffcf4b7694b7cc0d2444cd8c414
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0.0-p195
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Stefano Zanella
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
# Minitest::Filesystem
|
2
|
+
|
3
|
+
[](http://badge.fury.io/rb/minitest-filesystem)
|
4
|
+
[](https://travis-ci.org/stefanozanella/minitest-filesystem)
|
5
|
+
[](https://codeclimate.com/github/stefanozanella/minitest-filesystem)
|
6
|
+
[](https://coveralls.io/r/stefanozanella/minitest-filesystem?branch=master)
|
7
|
+
|
8
|
+
Adds assertions and expectations to check filesystem content in a communicative way.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
gem 'minitest-filesystem'
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install minitest-filesystem
|
23
|
+
|
24
|
+
Once the gem is installed, just add this line to your `test_helper.rb`:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
require 'minitest/filesystem'
|
28
|
+
```
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
Let's suppose the following filesystem structure exists:
|
33
|
+
|
34
|
+
* `root_dir/`
|
35
|
+
* `file_1`
|
36
|
+
* `file_2`
|
37
|
+
* `subdir_1/`
|
38
|
+
* `subfile_1`
|
39
|
+
* `subfile_2`
|
40
|
+
* `subsubdir_1/`
|
41
|
+
* `subdir_2/`
|
42
|
+
|
43
|
+
You can check if `root_dir` contains a specific structure:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
assert_contains_filesystem("root_dir") do
|
47
|
+
file "file_1"
|
48
|
+
dir "subdir_1" do
|
49
|
+
file "subfile_1"
|
50
|
+
end
|
51
|
+
dir "subdir_2"
|
52
|
+
end
|
53
|
+
```
|
54
|
+
|
55
|
+
or, if you prefer the expectation style:
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
filesystem {
|
59
|
+
file "file_1"
|
60
|
+
dir "subdir_1" do
|
61
|
+
file "subfile_1"
|
62
|
+
end
|
63
|
+
dir "subdir_2"
|
64
|
+
}.must_exist_within "root_dir"
|
65
|
+
```
|
66
|
+
|
67
|
+
Note that the match **need not to be exact** (i.e. there can be other files and
|
68
|
+
directories inside `root_dir` that the matcher won't care about).
|
69
|
+
|
70
|
+
## Contributing
|
71
|
+
|
72
|
+
1. Fork it
|
73
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
74
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
75
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
76
|
+
5. Create new Pull Request
|
77
|
+
|
78
|
+
## Changelog
|
79
|
+
|
80
|
+
### 0.0.1
|
81
|
+
|
82
|
+
* Extract assertion and matcher from current projects
|
data/Rakefile
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
module MiniTest
|
4
|
+
module FileSystem
|
5
|
+
class Matcher
|
6
|
+
def initialize(root, &block)
|
7
|
+
@actual_tree = MatchingTree.new(root)
|
8
|
+
@expected_tree = block
|
9
|
+
@is_matching = true
|
10
|
+
end
|
11
|
+
|
12
|
+
def file(file)
|
13
|
+
entry(:file, file) && is_a?(:file, file)
|
14
|
+
end
|
15
|
+
|
16
|
+
def dir(dir, &block)
|
17
|
+
matcher = self.class.new(@actual_tree.root + dir, &block) if block_given?
|
18
|
+
|
19
|
+
entry(:directory, dir) && is_a?(:directory, dir) && subtree(matcher)
|
20
|
+
end
|
21
|
+
|
22
|
+
def entry(kind = :entry, entry)
|
23
|
+
@is_matching = @is_matching && @actual_tree.include?(entry)
|
24
|
+
set_failure_msg_for(kind, entry) unless @is_matching
|
25
|
+
|
26
|
+
@is_matching
|
27
|
+
end
|
28
|
+
|
29
|
+
def match_found?
|
30
|
+
instance_eval(&@expected_tree)
|
31
|
+
@is_matching
|
32
|
+
end
|
33
|
+
|
34
|
+
def message
|
35
|
+
@failure_msg || ""
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def subtree(matcher)
|
41
|
+
@is_matching = @is_matching && matcher.match_found? if matcher
|
42
|
+
set_failure_msg(matcher.message) unless @is_matching
|
43
|
+
|
44
|
+
@is_matching
|
45
|
+
end
|
46
|
+
|
47
|
+
def is_a?(kind, entry)
|
48
|
+
@is_matching = @is_matching && (@actual_tree.is_a?(kind, entry))
|
49
|
+
set_mismatch_failure_msg_for(kind, entry) unless @is_matching
|
50
|
+
|
51
|
+
@is_matching
|
52
|
+
end
|
53
|
+
|
54
|
+
def set_failure_msg_for(kind, entry)
|
55
|
+
set_failure_msg "Expected `#{@actual_tree.root}` to contain #{kind} `#{entry}`."
|
56
|
+
end
|
57
|
+
|
58
|
+
def set_failure_msg(msg)
|
59
|
+
@failure_msg ||= msg
|
60
|
+
end
|
61
|
+
|
62
|
+
def set_mismatch_failure_msg_for(kind, entry)
|
63
|
+
@failure_msg ||=
|
64
|
+
"Expected `#{entry}` to be a #{kind}, but it was not."
|
65
|
+
end
|
66
|
+
|
67
|
+
class MatchingTree
|
68
|
+
attr_reader :root
|
69
|
+
|
70
|
+
def initialize(root)
|
71
|
+
@root = Pathname.new(root)
|
72
|
+
@tree = expand_tree_under @root
|
73
|
+
end
|
74
|
+
|
75
|
+
def include?(entry)
|
76
|
+
@tree.include?(root_slash(entry))
|
77
|
+
end
|
78
|
+
|
79
|
+
def is_a?(kind, entry)
|
80
|
+
(root_slash entry).send("#{kind}?")
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def expand_tree_under(dir)
|
86
|
+
Pathname.glob(dir.join("**/*"))
|
87
|
+
end
|
88
|
+
|
89
|
+
def root_slash(file)
|
90
|
+
@root + Pathname.new(file)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require "minitest/filesystem/version"
|
2
|
+
require "minitest/filesystem/matcher"
|
3
|
+
|
4
|
+
module MiniTest::Assertions
|
5
|
+
def assert_contains_filesystem(dir, msg = nil, &block)
|
6
|
+
matcher = MiniTest::FileSystem::Matcher.new(dir, &block)
|
7
|
+
assert matcher.match_found?, msg || matcher.message
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'minitest/filesystem/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "minitest-filesystem"
|
8
|
+
gem.version = Minitest::Filesystem::VERSION
|
9
|
+
gem.authors = ["Stefano Zanella"]
|
10
|
+
gem.email = ["zanella.stefano@gmail.com"]
|
11
|
+
gem.description = %q{Minitest exstension to check filesystem contents}
|
12
|
+
gem.summary = %q{Adds assertions and expectations to check the content
|
13
|
+
of a filesystem tree with minitest}
|
14
|
+
gem.homepage = "https://github.com/stefanozanella/minitest-filesystem"
|
15
|
+
gem.license = "MIT"
|
16
|
+
|
17
|
+
gem.files = `git ls-files`.split($/)
|
18
|
+
gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
gem.test_files = gem.files.grep(%r{^(test|gem|features)/})
|
20
|
+
gem.require_paths = ["lib"]
|
21
|
+
|
22
|
+
gem.add_development_dependency "bundler", "~> 1.3"
|
23
|
+
gem.add_development_dependency "rake"
|
24
|
+
gem.add_development_dependency "minitest"
|
25
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'tmpdir'
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
describe "assert_contains_filesystem" do
|
6
|
+
before do
|
7
|
+
@root_dir = Pathname.new(Dir.mktmpdir('minitestfs'))
|
8
|
+
|
9
|
+
(@root_dir + 'a_directory').mkdir
|
10
|
+
(@root_dir + 'a_subdirectory').mkdir
|
11
|
+
(@root_dir + 'not_a_file').mkdir
|
12
|
+
(@root_dir + 'unchecked_dir').mkdir
|
13
|
+
|
14
|
+
FileUtils.touch(@root_dir + 'a_file')
|
15
|
+
FileUtils.touch(@root_dir + 'not_a_dir')
|
16
|
+
FileUtils.touch(@root_dir + 'a_subdirectory' + 'another_file')
|
17
|
+
FileUtils.touch(@root_dir + 'unchecked_file')
|
18
|
+
end
|
19
|
+
|
20
|
+
after do
|
21
|
+
FileUtils.rm_rf @root_dir
|
22
|
+
end
|
23
|
+
|
24
|
+
it "passes with empty expected tree" do
|
25
|
+
assert_contains_filesystem(@root_dir) {}
|
26
|
+
end
|
27
|
+
|
28
|
+
it "passes when single file found" do
|
29
|
+
assert_contains_filesystem(@root_dir) do
|
30
|
+
file "a_file"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it "passes when single directory found" do
|
35
|
+
assert_contains_filesystem(@root_dir) do
|
36
|
+
dir "a_directory"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
it "passes when a file within a subdirectory is found" do
|
41
|
+
assert_contains_filesystem(@root_dir) do
|
42
|
+
dir "a_subdirectory" do
|
43
|
+
file "another_file"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it "fails when an expected file isn't found" do
|
49
|
+
l = lambda { assert_contains_filesystem(@root_dir) do
|
50
|
+
file "foo"
|
51
|
+
end }
|
52
|
+
|
53
|
+
error = assert_raises(MiniTest::Assertion, &l)
|
54
|
+
error.message.must_match(/expected `#{@root_dir}` to contain file `foo`/im)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "fails when an expected directory isn't found" do
|
58
|
+
l = lambda { assert_contains_filesystem(@root_dir) do
|
59
|
+
dir "bar"
|
60
|
+
end }
|
61
|
+
|
62
|
+
error = assert_raises(MiniTest::Assertion, &l)
|
63
|
+
error.message.must_match(/expected `#{@root_dir}` to contain directory `bar`/im)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "fails when an expected file within a subdirectory isn't found" do
|
67
|
+
l = lambda { assert_contains_filesystem(@root_dir) do
|
68
|
+
dir "a_subdirectory" do
|
69
|
+
file "missing_file"
|
70
|
+
end
|
71
|
+
end }
|
72
|
+
|
73
|
+
error = assert_raises(MiniTest::Assertion, &l)
|
74
|
+
error.message.must_match(
|
75
|
+
/expected `#{@root_dir + 'a_subdirectory'}` to contain file `missing_file`/im
|
76
|
+
)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "fails when a directory is expected to be a file" do
|
80
|
+
l = lambda { assert_contains_filesystem(@root_dir) do
|
81
|
+
file "not_a_file"
|
82
|
+
end }
|
83
|
+
|
84
|
+
error = assert_raises(MiniTest::Assertion, &l)
|
85
|
+
error.message.must_match(/expected `not_a_file` to be a file/im)
|
86
|
+
end
|
87
|
+
|
88
|
+
it "fails when a file is expected to be a directory" do
|
89
|
+
l = lambda { assert_contains_filesystem(@root_dir) do
|
90
|
+
dir "not_a_dir"
|
91
|
+
end }
|
92
|
+
|
93
|
+
error = assert_raises(MiniTest::Assertion, &l)
|
94
|
+
error.message.must_match(/expected `not_a_dir` to be a directory/im)
|
95
|
+
end
|
96
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: minitest-filesystem
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Stefano Zanella
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-06-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Minitest exstension to check filesystem contents
|
56
|
+
email:
|
57
|
+
- zanella.stefano@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- .ruby-version
|
64
|
+
- .travis.yml
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- lib/minitest/filesystem.rb
|
70
|
+
- lib/minitest/filesystem/matcher.rb
|
71
|
+
- lib/minitest/filesystem/version.rb
|
72
|
+
- minitest-filesystem.gemspec
|
73
|
+
- test/filesystem_test.rb
|
74
|
+
- test/test_helper.rb
|
75
|
+
homepage: https://github.com/stefanozanella/minitest-filesystem
|
76
|
+
licenses:
|
77
|
+
- MIT
|
78
|
+
metadata: {}
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 2.0.2
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: Adds assertions and expectations to check the content of a filesystem tree
|
99
|
+
with minitest
|
100
|
+
test_files:
|
101
|
+
- test/filesystem_test.rb
|
102
|
+
- test/test_helper.rb
|