Module: Minitest::Expectations
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Defined in: | lib/minitest/expectations.rb |
Overview
It’s where you hide your “assertions”.
Please note, because of the way that expectations are implemented, all expectations (eg must_equal) are dependent upon a thread local variable :current_spec
. If your specs rely on mixing threads into the specs themselves, you’re better off using assertions or the new _(value) wrapper. For example:
it "should still work in threads" do
my_threaded_thingy do
(1+1).must_equal 2 # bad
assert_equal 2, 1+1 # good
_(1 + 1).must_equal 2 # good
value(1 + 1).must_equal 2 # good, also #expect
_ { 1 + "1" }.must_raise TypeError # good
end
end
Instance Method Summary
- #assert_empty
- #assert_equal
- #assert_in_delta
- #assert_in_epsilon
- #assert_includes
- #assert_instance_of
- #assert_kind_of
- #assert_match
- #assert_nil
- #assert_operator
- #assert_output
- #assert_path_exists
-
#assert_pattern
See
Minitest::Assertions#assert_pattern_match
- #assert_raises
- #assert_respond_to
- #assert_same
- #assert_silent
- #assert_throws
- #refute_empty
- #refute_equal
- #refute_in_delta
- #refute_in_epsilon
- #refute_includes
- #refute_instance_of
- #refute_kind_of
- #refute_match
- #refute_nil
- #refute_operator
- #refute_path_exists
-
#refute_pattern
See
Minitest::Assertions#refute_pattern_match
- #refute_respond_to
- #refute_same
Instance Method Details
#assert_empty
# File 'lib/minitest/expectations.rb', line 29
infect_an_assertion :assert_empty, :must_be_empty, :unary
#assert_equal
# File 'lib/minitest/expectations.rb', line 38
infect_an_assertion :assert_equal, :must_equal
#assert_in_delta
# File 'lib/minitest/expectations.rb', line 47
infect_an_assertion :assert_in_delta, :must_be_close_to
#assert_in_epsilon
See Assertions#assert_in_epsilon
_(n).must_be_within_epsilon m [, epsilon]
:method: must_be_within_epsilon
# File 'lib/minitest/expectations.rb', line 58
infect_an_assertion :assert_in_epsilon, :must_be_within_epsilon
#assert_includes
# File 'lib/minitest/expectations.rb', line 67
infect_an_assertion :assert_includes, :must_include, :reverse
#assert_instance_of
# File 'lib/minitest/expectations.rb', line 76
infect_an_assertion :assert_instance_of, :must_be_instance_of
#assert_kind_of
# File 'lib/minitest/expectations.rb', line 85
infect_an_assertion :assert_kind_of, :must_be_kind_of
#assert_match
# File 'lib/minitest/expectations.rb', line 94
infect_an_assertion :assert_match, :must_match
#assert_nil
# File 'lib/minitest/expectations.rb', line 103
infect_an_assertion :assert_nil, :must_be_nil, :unary
#assert_operator
See Assertions#assert_operator
_(n).must_be :<=, 42
This can also do predicates:
_(str).must_be :empty?
:method: must_be
# File 'lib/minitest/expectations.rb', line 116
infect_an_assertion :assert_operator, :must_be, :reverse
#assert_output
# File 'lib/minitest/expectations.rb', line 125
infect_an_assertion :assert_output, :must_output, :block
#assert_path_exists
# File 'lib/minitest/expectations.rb', line 188
infect_an_assertion :assert_path_exists, :path_must_exist, :unary
#assert_pattern
See Minitest::Assertions#assert_pattern_match
_ { ... }.must_pattern_match [...]
:method: must_pattern_match
# File 'lib/minitest/expectations.rb', line 134
infect_an_assertion :assert_pattern, :must_pattern_match, :block
#assert_raises
# File 'lib/minitest/expectations.rb', line 143
infect_an_assertion :assert_raises, :must_raise, :block
#assert_respond_to
# File 'lib/minitest/expectations.rb', line 152
infect_an_assertion :assert_respond_to, :must_respond_to, :reverse
#assert_same
# File 'lib/minitest/expectations.rb', line 161
infect_an_assertion :assert_same, :must_be_same_as
#assert_silent
# File 'lib/minitest/expectations.rb', line 170
infect_an_assertion :assert_silent, :must_be_silent, :block
#assert_throws
# File 'lib/minitest/expectations.rb', line 179
infect_an_assertion :assert_throws, :must_throw, :block
#refute_empty
# File 'lib/minitest/expectations.rb', line 206
infect_an_assertion :refute_empty, :wont_be_empty, :unary
#refute_equal
# File 'lib/minitest/expectations.rb', line 215
infect_an_assertion :refute_equal, :wont_equal
#refute_in_delta
# File 'lib/minitest/expectations.rb', line 224
infect_an_assertion :refute_in_delta, :wont_be_close_to
#refute_in_epsilon
See Assertions#refute_in_epsilon
_(n).wont_be_within_epsilon m [, epsilon]
:method: wont_be_within_epsilon
# File 'lib/minitest/expectations.rb', line 235
infect_an_assertion :refute_in_epsilon, :wont_be_within_epsilon
#refute_includes
# File 'lib/minitest/expectations.rb', line 244
infect_an_assertion :refute_includes, :wont_include, :reverse
#refute_instance_of
# File 'lib/minitest/expectations.rb', line 253
infect_an_assertion :refute_instance_of, :wont_be_instance_of
#refute_kind_of
# File 'lib/minitest/expectations.rb', line 262
infect_an_assertion :refute_kind_of, :wont_be_kind_of
#refute_match
# File 'lib/minitest/expectations.rb', line 271
infect_an_assertion :refute_match, :wont_match
#refute_nil
# File 'lib/minitest/expectations.rb', line 280
infect_an_assertion :refute_nil, :wont_be_nil, :unary
#refute_operator
See Assertions#refute_operator
_(n).wont_be :<=, 42
This can also do predicates:
str.wont_be :empty?
:method: wont_be
# File 'lib/minitest/expectations.rb', line 293
infect_an_assertion :refute_operator, :wont_be, :reverse
#refute_path_exists
# File 'lib/minitest/expectations.rb', line 197
infect_an_assertion :refute_path_exists, :path_wont_exist, :unary
#refute_pattern
See Minitest::Assertions#refute_pattern_match
_ { ... }.wont_pattern_match [...]
:method: wont_pattern_match
# File 'lib/minitest/expectations.rb', line 302
infect_an_assertion :refute_pattern, :wont_pattern_match, :block
#refute_respond_to
# File 'lib/minitest/expectations.rb', line 311
infect_an_assertion :refute_respond_to, :wont_respond_to, :reverse
#refute_same
# File 'lib/minitest/expectations.rb', line 320
infect_an_assertion :refute_same, :wont_be_same_as