Skip to content

Commit

Permalink
+ Added expectations #path_must_exist and #path_wont_exist. Not thril…
Browse files Browse the repository at this point in the history
…led with the names.

[git-p4: depot-paths = "//src/minitest/dev/": change = 12354]
  • Loading branch information
zenspider committed Oct 20, 2019
1 parent dcac10a commit c07a593
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
18 changes: 18 additions & 0 deletions lib/minitest/expectations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,24 @@ module Minitest::Expectations

infect_an_assertion :assert_throws, :must_throw, :block

##
# See Minitest::Assertions#assert_path_exists
#
# _(some_path).path_must_exist
#
# :method: path_must_exist

infect_an_assertion :assert_path_exists, :path_must_exist, :unary

##
# See Minitest::Assertions#refute_path_exists
#
# _(some_path).path_wont_exist
#
# :method: path_wont_exist

infect_an_assertion :refute_path_exists, :path_wont_exist, :unary

##
# See Minitest::Assertions#refute_empty
#
Expand Down
29 changes: 25 additions & 4 deletions test/minitest/test_minitest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,26 @@ def assert_triggered expected = "blah", klass = Minitest::Assertion
end
end

it "needs to check for file existence" do
@assertion_count = 3

_(_(__FILE__).path_must_exist).must_equal true

assert_triggered "Expected path 'blah' to exist." do
_("blah").path_must_exist
end
end

it "needs to check for file non-existence" do
@assertion_count = 3

_(_("blah").path_wont_exist).must_equal false

assert_triggered "Expected path '#{__FILE__}' to not exist." do
_(__FILE__).path_wont_exist
end
end

it "needs to be sensible about must_include order" do
@assertion_count += 3 # must_include is 2 assertions

Expand Down Expand Up @@ -129,10 +149,10 @@ def assert_triggered expected = "blah", klass = Minitest::Assertion

@assertion_count = 2

methods = Object.public_instance_methods.find_all { |n| n =~ /^must|^wont/ }
methods = Minitest::Expectations.public_instance_methods.grep(/must|wont/)
methods.map!(&:to_s) if Symbol === methods.first

musts, wonts = methods.sort.partition { |m| m =~ /^must/ }
musts, wonts = methods.sort.partition { |m| m =~ /must/ }

expected_musts = %w[must_be
must_be_close_to
Expand All @@ -150,11 +170,12 @@ def assert_triggered expected = "blah", klass = Minitest::Assertion
must_output
must_raise
must_respond_to
must_throw]
must_throw
path_must_exist]

bad = %w[not raise throw send output be_silent]

expected_wonts = expected_musts.map { |m| m.sub(/^must/, "wont") }
expected_wonts = expected_musts.map { |m| m.sub(/must/, "wont") }.sort
expected_wonts.reject! { |m| m =~ /wont_#{Regexp.union(*bad)}/ }

_(musts).must_equal expected_musts
Expand Down

0 comments on commit c07a593

Please sign in to comment.