module Minitest::Expectations

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

Public Instance Methods

must_be() click to toggle source

See Minitest::Assertions#assert_operator

_(n).must_be :<=, 42

This can also do predicates:

_(str).must_be :empty?
# File minitest-5.15.0/lib/minitest/expectations.rb, line 116
infect_an_assertion :assert_operator, :must_be, :reverse
must_be_close_to() click to toggle source

See Minitest::Assertions#assert_in_delta

_(n).must_be_close_to m [, delta]
# File minitest-5.15.0/lib/minitest/expectations.rb, line 47
infect_an_assertion :assert_in_delta, :must_be_close_to
must_be_empty() click to toggle source

See Minitest::Assertions#assert_empty.

_(collection).must_be_empty
# File minitest-5.15.0/lib/minitest/expectations.rb, line 29
infect_an_assertion :assert_empty, :must_be_empty, :unary
must_be_instance_of() click to toggle source

See Minitest::Assertions#assert_instance_of

_(obj).must_be_instance_of klass
# File minitest-5.15.0/lib/minitest/expectations.rb, line 76
infect_an_assertion :assert_instance_of, :must_be_instance_of
must_be_kind_of() click to toggle source

See Minitest::Assertions#assert_kind_of

_(obj).must_be_kind_of mod
# File minitest-5.15.0/lib/minitest/expectations.rb, line 85
infect_an_assertion :assert_kind_of, :must_be_kind_of
must_be_nil() click to toggle source

See Minitest::Assertions#assert_nil

_(obj).must_be_nil
# File minitest-5.15.0/lib/minitest/expectations.rb, line 103
infect_an_assertion :assert_nil, :must_be_nil, :unary
must_be_same_as() click to toggle source

See Minitest::Assertions#assert_same

_(a).must_be_same_as b
# File minitest-5.15.0/lib/minitest/expectations.rb, line 152
infect_an_assertion :assert_same, :must_be_same_as
must_be_silent() click to toggle source

See Minitest::Assertions#assert_silent

_ { ... }.must_be_silent
# File minitest-5.15.0/lib/minitest/expectations.rb, line 161
infect_an_assertion :assert_silent, :must_be_silent, :block
must_be_within_epsilon() click to toggle source

See Minitest::Assertions#assert_in_epsilon

_(n).must_be_within_epsilon m [, epsilon]
# File minitest-5.15.0/lib/minitest/expectations.rb, line 58
infect_an_assertion :assert_in_epsilon, :must_be_within_epsilon
must_equal() click to toggle source

See Minitest::Assertions#assert_equal

_(a).must_equal b
# File minitest-5.15.0/lib/minitest/expectations.rb, line 38
infect_an_assertion :assert_equal, :must_equal
must_include() click to toggle source

See Minitest::Assertions#assert_includes

_(collection).must_include obj
# File minitest-5.15.0/lib/minitest/expectations.rb, line 67
infect_an_assertion :assert_includes, :must_include, :reverse
must_match() click to toggle source

See Minitest::Assertions#assert_match

_(a).must_match b
# File minitest-5.15.0/lib/minitest/expectations.rb, line 94
infect_an_assertion :assert_match, :must_match
must_output() click to toggle source

See Minitest::Assertions#assert_output

_ { ... }.must_output out_or_nil [, err]
# File minitest-5.15.0/lib/minitest/expectations.rb, line 125
infect_an_assertion :assert_output, :must_output, :block
must_raise() click to toggle source

See Minitest::Assertions#assert_raises

_ { ... }.must_raise exception
# File minitest-5.15.0/lib/minitest/expectations.rb, line 134
infect_an_assertion :assert_raises, :must_raise, :block
must_respond_to() click to toggle source

See Minitest::Assertions#assert_respond_to

_(obj).must_respond_to msg
# File minitest-5.15.0/lib/minitest/expectations.rb, line 143
infect_an_assertion :assert_respond_to, :must_respond_to, :reverse
must_throw() click to toggle source

See Minitest::Assertions#assert_throws

_ { ... }.must_throw sym
# File minitest-5.15.0/lib/minitest/expectations.rb, line 170
infect_an_assertion :assert_throws, :must_throw, :block
path_must_exist() click to toggle source

See Minitest::Assertions#assert_path_exists

_(some_path).path_must_exist
# File minitest-5.15.0/lib/minitest/expectations.rb, line 179
infect_an_assertion :assert_path_exists, :path_must_exist, :unary
path_wont_exist() click to toggle source

See Minitest::Assertions#refute_path_exists

_(some_path).path_wont_exist
# File minitest-5.15.0/lib/minitest/expectations.rb, line 188
infect_an_assertion :refute_path_exists, :path_wont_exist, :unary
wont_be() click to toggle source

See Minitest::Assertions#refute_operator

_(n).wont_be :<=, 42

This can also do predicates:

str.wont_be :empty?
# File minitest-5.15.0/lib/minitest/expectations.rb, line 284
infect_an_assertion :refute_operator, :wont_be, :reverse
wont_be_close_to() click to toggle source

See Minitest::Assertions#refute_in_delta

_(n).wont_be_close_to m [, delta]
# File minitest-5.15.0/lib/minitest/expectations.rb, line 215
infect_an_assertion :refute_in_delta, :wont_be_close_to
wont_be_empty() click to toggle source

See Minitest::Assertions#refute_empty

_(collection).wont_be_empty
# File minitest-5.15.0/lib/minitest/expectations.rb, line 197
infect_an_assertion :refute_empty, :wont_be_empty, :unary
wont_be_instance_of() click to toggle source

See Minitest::Assertions#refute_instance_of

_(obj).wont_be_instance_of klass
# File minitest-5.15.0/lib/minitest/expectations.rb, line 244
infect_an_assertion :refute_instance_of, :wont_be_instance_of
wont_be_kind_of() click to toggle source

See Minitest::Assertions#refute_kind_of

_(obj).wont_be_kind_of mod
# File minitest-5.15.0/lib/minitest/expectations.rb, line 253
infect_an_assertion :refute_kind_of, :wont_be_kind_of
wont_be_nil() click to toggle source

See Minitest::Assertions#refute_nil

_(obj).wont_be_nil
# File minitest-5.15.0/lib/minitest/expectations.rb, line 271
infect_an_assertion :refute_nil, :wont_be_nil, :unary
wont_be_same_as() click to toggle source

See Minitest::Assertions#refute_same

_(a).wont_be_same_as b
# File minitest-5.15.0/lib/minitest/expectations.rb, line 302
infect_an_assertion :refute_same, :wont_be_same_as
wont_be_within_epsilon() click to toggle source

See Minitest::Assertions#refute_in_epsilon

_(n).wont_be_within_epsilon m [, epsilon]
# File minitest-5.15.0/lib/minitest/expectations.rb, line 226
infect_an_assertion :refute_in_epsilon, :wont_be_within_epsilon
wont_equal() click to toggle source

See Minitest::Assertions#refute_equal

_(a).wont_equal b
# File minitest-5.15.0/lib/minitest/expectations.rb, line 206
infect_an_assertion :refute_equal, :wont_equal
wont_include() click to toggle source

See Minitest::Assertions#refute_includes

_(collection).wont_include obj
# File minitest-5.15.0/lib/minitest/expectations.rb, line 235
infect_an_assertion :refute_includes, :wont_include, :reverse
wont_match() click to toggle source

See Minitest::Assertions#refute_match

_(a).wont_match b
# File minitest-5.15.0/lib/minitest/expectations.rb, line 262
infect_an_assertion :refute_match, :wont_match
wont_respond_to() click to toggle source

See Minitest::Assertions#refute_respond_to

_(obj).wont_respond_to msg
# File minitest-5.15.0/lib/minitest/expectations.rb, line 293
infect_an_assertion :refute_respond_to, :wont_respond_to, :reverse