minitest-filesystem 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b364d783dce84d3efbc20abb86664ed9b236b416
4
- data.tar.gz: 094022ba019ef0e6035cb831244e63a389317b8f
3
+ metadata.gz: 06e28053de722c8cc02a8e8679ec05b41fe86e39
4
+ data.tar.gz: f8e11b3bd7ff63311b7699a9f739f7e91bcac9d1
5
5
  SHA512:
6
- metadata.gz: 9334f162c83d5baf45d0f00ca8798e2933fca944ac6eee2fb41098062e7a3d1d45dacb76cec9d8d6800062f58b35c45a462df4b37c34d91dd9b81cc310c24fc2
7
- data.tar.gz: 5b4bd753d6241f2104ce3c3e8b876190130274dc81c66c8baecf644c48b0711dddd903d4c9ccf249c62fa8c0a475cc33521a6ffcf4b7694b7cc0d2444cd8c414
6
+ metadata.gz: 5375f8b89900b5e6a05eb32289cb8aaf4bf2e144ccf302890dcbd08958f1e8b7d93bdea120be1ebbd22b1fc0fdee7a3134d69d0ff34fc95a9017786ab165d69c
7
+ data.tar.gz: d58bdf3707630ca24a3a26901bcbff36aaf19439e8e9eadbca43e5d40629db6743acacf6fb66d7acdc126151279cf3e2959523b05567b709bacc863b68432a67
data/.gitignore CHANGED
@@ -1,8 +1,12 @@
1
+ .DS_Store
2
+ *.swp
3
+ *.swo
1
4
  *.gem
2
5
  *.rbc
3
6
  .bundle
4
7
  .config
5
8
  .yardoc
9
+ .yardopts
6
10
  Gemfile.lock
7
11
  InstalledFiles
8
12
  _yardoc
data/.travis.yml CHANGED
@@ -7,7 +7,7 @@ rvm:
7
7
  - jruby-19mode
8
8
  - rbx-19mode
9
9
 
10
- install: bundle install --path vendor/bundle
10
+ bundler_args: --path vendor/bundle
11
11
 
12
12
  script:
13
13
  - bundle exec rake test
data/README.md CHANGED
@@ -80,3 +80,9 @@ directories inside `root_dir` that the matcher won't care about).
80
80
  ### 0.0.1
81
81
 
82
82
  * Extract assertion and matcher from current projects
83
+
84
+ ### 0.1.0
85
+
86
+ * Refactor existing code
87
+ * Add more tests around assertion
88
+ * Infect `must_exist_within` expectation
@@ -6,4 +6,12 @@ module MiniTest::Assertions
6
6
  matcher = MiniTest::FileSystem::Matcher.new(dir, &block)
7
7
  assert matcher.match_found?, msg || matcher.message
8
8
  end
9
+
10
+ def filesystem(&block)
11
+ block
12
+ end
13
+ end
14
+
15
+ module MiniTest::Expectations
16
+ infect_an_assertion :assert_contains_filesystem, :must_exist_within
9
17
  end
@@ -14,18 +14,11 @@ module MiniTest
14
14
  end
15
15
 
16
16
  def dir(dir, &block)
17
- matcher = self.class.new(@actual_tree.root + dir, &block) if block_given?
17
+ matcher = self.class.new(@actual_tree.expand_path(dir), &block) if block_given?
18
18
 
19
19
  entry(:directory, dir) && is_a?(:directory, dir) && subtree(matcher)
20
20
  end
21
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
22
  def match_found?
30
23
  instance_eval(&@expected_tree)
31
24
  @is_matching
@@ -37,31 +30,39 @@ module MiniTest
37
30
 
38
31
  private
39
32
 
40
- def subtree(matcher)
41
- @is_matching = @is_matching && matcher.match_found? if matcher
42
- set_failure_msg(matcher.message) unless @is_matching
33
+ def entry(kind = :entry, entry)
34
+ update_matching_status(
35
+ @actual_tree.include?(entry),
36
+ not_found_msg_for(kind, entry))
37
+ end
43
38
 
44
- @is_matching
39
+ def subtree(matcher)
40
+ update_matching_status(matcher.match_found?, matcher.message) if matcher
45
41
  end
46
42
 
47
43
  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
44
+ update_matching_status(
45
+ @actual_tree.is_a?(kind, entry),
46
+ mismatch_msg_for(kind, entry))
47
+ end
48
+
49
+ def update_matching_status(check, msg)
50
+ @is_matching = @is_matching && check
51
+ set_failure_msg(msg) unless @is_matching
50
52
 
51
53
  @is_matching
52
54
  end
53
55
 
54
- def set_failure_msg_for(kind, entry)
55
- set_failure_msg "Expected `#{@actual_tree.root}` to contain #{kind} `#{entry}`."
56
+ def not_found_msg_for(kind, entry)
57
+ "Expected `#{@actual_tree.root}` to contain #{kind} `#{entry}`."
56
58
  end
57
59
 
58
- def set_failure_msg(msg)
59
- @failure_msg ||= msg
60
+ def mismatch_msg_for(kind, entry)
61
+ "Expected `#{entry}` to be a #{kind}, but it was not."
60
62
  end
61
63
 
62
- def set_mismatch_failure_msg_for(kind, entry)
63
- @failure_msg ||=
64
- "Expected `#{entry}` to be a #{kind}, but it was not."
64
+ def set_failure_msg(msg)
65
+ @failure_msg ||= msg
65
66
  end
66
67
 
67
68
  class MatchingTree
@@ -73,11 +74,15 @@ module MiniTest
73
74
  end
74
75
 
75
76
  def include?(entry)
76
- @tree.include?(root_slash(entry))
77
+ @tree.include?(expand_path(entry))
77
78
  end
78
79
 
79
80
  def is_a?(kind, entry)
80
- (root_slash entry).send("#{kind}?")
81
+ (expand_path entry).send("#{kind}?")
82
+ end
83
+
84
+ def expand_path(file)
85
+ @root + Pathname.new(file)
81
86
  end
82
87
 
83
88
  private
@@ -85,10 +90,6 @@ module MiniTest
85
90
  def expand_tree_under(dir)
86
91
  Pathname.glob(dir.join("**/*"))
87
92
  end
88
-
89
- def root_slash(file)
90
- @root + Pathname.new(file)
91
- end
92
93
  end
93
94
  end
94
95
  end
@@ -1,5 +1,5 @@
1
1
  module Minitest
2
2
  module Filesystem
3
- VERSION = "0.0.1"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -22,4 +22,5 @@ Gem::Specification.new do |gem|
22
22
  gem.add_development_dependency "bundler", "~> 1.3"
23
23
  gem.add_development_dependency "rake"
24
24
  gem.add_development_dependency "minitest"
25
+ gem.add_development_dependency "coveralls"
25
26
  end
@@ -1,22 +1,24 @@
1
1
  require 'test_helper'
2
+
2
3
  require 'tmpdir'
3
4
  require 'fileutils'
4
5
 
5
6
  describe "assert_contains_filesystem" do
6
7
  before do
7
8
  @root_dir = Pathname.new(Dir.mktmpdir('minitestfs'))
8
-
9
+
9
10
  (@root_dir + 'a_directory').mkdir
10
11
  (@root_dir + 'a_subdirectory').mkdir
12
+ (@root_dir + 'a_subdirectory' + 'deeper_subdirectory').mkdir
11
13
  (@root_dir + 'not_a_file').mkdir
12
14
  (@root_dir + 'unchecked_dir').mkdir
13
-
15
+
14
16
  FileUtils.touch(@root_dir + 'a_file')
15
17
  FileUtils.touch(@root_dir + 'not_a_dir')
16
- FileUtils.touch(@root_dir + 'a_subdirectory' + 'another_file')
18
+ FileUtils.touch(@root_dir + 'a_subdirectory' + 'deeper_subdirectory' + 'another_file')
17
19
  FileUtils.touch(@root_dir + 'unchecked_file')
18
20
  end
19
-
21
+
20
22
  after do
21
23
  FileUtils.rm_rf @root_dir
22
24
  end
@@ -37,10 +39,12 @@ describe "assert_contains_filesystem" do
37
39
  end
38
40
  end
39
41
 
40
- it "passes when a file within a subdirectory is found" do
42
+ it "passes when a file within a nested subtree is found" do
41
43
  assert_contains_filesystem(@root_dir) do
42
44
  dir "a_subdirectory" do
43
- file "another_file"
45
+ dir "deeper_subdirectory" do
46
+ file "another_file"
47
+ end
44
48
  end
45
49
  end
46
50
  end
@@ -72,8 +76,7 @@ describe "assert_contains_filesystem" do
72
76
 
73
77
  error = assert_raises(MiniTest::Assertion, &l)
74
78
  error.message.must_match(
75
- /expected `#{@root_dir + 'a_subdirectory'}` to contain file `missing_file`/im
76
- )
79
+ /expected `#{@root_dir + 'a_subdirectory'}` to contain file `missing_file`/im)
77
80
  end
78
81
 
79
82
  it "fails when a directory is expected to be a file" do
@@ -93,4 +96,15 @@ describe "assert_contains_filesystem" do
93
96
  error = assert_raises(MiniTest::Assertion, &l)
94
97
  error.message.must_match(/expected `not_a_dir` to be a directory/im)
95
98
  end
99
+
100
+ it "allows to print custom error messages" do
101
+ failure_msg = "I really miss this file a lot"
102
+
103
+ l = lambda { assert_contains_filesystem(@root_dir, failure_msg) do
104
+ file "baz"
105
+ end }
106
+
107
+ error = assert_raises(MiniTest::Assertion, &l)
108
+ error.message.must_equal(failure_msg)
109
+ end
96
110
  end
@@ -0,0 +1,48 @@
1
+ require 'test_helper'
2
+
3
+ require 'tmpdir'
4
+ require 'fileutils'
5
+
6
+ describe "filesystem must_exist_within" do
7
+ before do
8
+ @root_dir = Pathname.new(Dir.mktmpdir('minitestfs'))
9
+
10
+ (@root_dir + 'a_directory').mkdir
11
+ (@root_dir + 'a_subdirectory').mkdir
12
+ (@root_dir + 'a_subdirectory' + 'deeper_subdirectory').mkdir
13
+ (@root_dir + 'not_a_file').mkdir
14
+ (@root_dir + 'unchecked_dir').mkdir
15
+
16
+ FileUtils.touch(@root_dir + 'a_file')
17
+ FileUtils.touch(@root_dir + 'not_a_dir')
18
+ FileUtils.touch(@root_dir + 'a_subdirectory' + 'deeper_subdirectory' + 'another_file')
19
+ FileUtils.touch(@root_dir + 'unchecked_file')
20
+ end
21
+
22
+ after do
23
+ FileUtils.rm_rf @root_dir
24
+ end
25
+
26
+ it "passes when the expected tree is found" do
27
+ filesystem {
28
+ file "a_file"
29
+ dir "a_subdirectory" do
30
+ dir "deeper_subdirectory" do
31
+ file "another_file"
32
+ end
33
+ end
34
+ }.must_exist_within(@root_dir)
35
+ end
36
+
37
+ it "fails when the expected tree is not found" do
38
+ l = lambda { filesystem {
39
+ file "a_file"
40
+ dir "a_subdirectory"
41
+ file "missing_file"
42
+ }.must_exist_within(@root_dir) }
43
+
44
+ error = assert_raises(MiniTest::Assertion, &l)
45
+ error.message.must_match(
46
+ /expected `#{@root_dir}` to contain file `missing_file`/im)
47
+ end
48
+ end
data/test/test_helper.rb CHANGED
@@ -1,3 +1,6 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
1
4
  require 'minitest/autorun'
2
5
  require 'minitest/spec'
3
6
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minitest-filesystem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefano Zanella
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: coveralls
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  description: Minitest exstension to check filesystem contents
56
70
  email:
57
71
  - zanella.stefano@gmail.com
@@ -70,7 +84,8 @@ files:
70
84
  - lib/minitest/filesystem/matcher.rb
71
85
  - lib/minitest/filesystem/version.rb
72
86
  - minitest-filesystem.gemspec
73
- - test/filesystem_test.rb
87
+ - test/assertion_test.rb
88
+ - test/expectation_test.rb
74
89
  - test/test_helper.rb
75
90
  homepage: https://github.com/stefanozanella/minitest-filesystem
76
91
  licenses:
@@ -98,5 +113,6 @@ specification_version: 4
98
113
  summary: Adds assertions and expectations to check the content of a filesystem tree
99
114
  with minitest
100
115
  test_files:
101
- - test/filesystem_test.rb
116
+ - test/assertion_test.rb
117
+ - test/expectation_test.rb
102
118
  - test/test_helper.rb