Skip to content

Commit

Permalink
+ Finally added assert_path_exists and refute_path_exists. (deivid-ro…
Browse files Browse the repository at this point in the history
…driguez)

[git-p4: depot-paths = "//src/minitest/dev/": change = 12352]
  • Loading branch information
zenspider committed Oct 20, 2019
1 parent e761784 commit 158bd6c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/minitest/assertions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,14 @@ def assert_throws sym, msg = nil
assert caught, message(msg) { default }
end

##
# Fails unless +path+ exists.

def assert_path_exists path, msg = nil
msg = message(msg) { "Expected path '#{path}' to exist" }
assert File.exist?(path), msg
end

##
# Captures $stdout and $stderr into strings:
#
Expand Down Expand Up @@ -738,6 +746,14 @@ def refute_same exp, act, msg = nil
refute exp.equal?(act), msg
end

##
# Fails if +path+ exists.

def refute_path_exists path, msg = nil
msg = message(msg) { "Expected path '#{path}' to not exist" }
refute File.exist?(path), msg
end

##
# Skips the current run. If run in verbose-mode, the skipped run
# gets listed at the end of the run but doesn't cause a failure
Expand Down
20 changes: 20 additions & 0 deletions test/minitest/test_minitest_assertions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,16 @@ def test_assert_throws_unthrown
end
end

def test_assert_path_exists
@tc.assert_path_exists __FILE__
end

def test_assert_path_exists_triggered
assert_triggered "Expected path 'blah' to exist." do
@tc.assert_path_exists "blah"
end
end

def test_capture_io
@assertion_count = 0

Expand Down Expand Up @@ -1171,6 +1181,16 @@ def test_refute_same_triggered
end
end

def test_refute_path_exists
@tc.refute_path_exists "blah"
end

def test_refute_path_exists_triggered
assert_triggered "Expected path '#{__FILE__}' to not exist." do
@tc.refute_path_exists __FILE__
end
end

def test_skip
@assertion_count = 0

Expand Down

0 comments on commit 158bd6c

Please sign in to comment.