Skip to content

Instantly share code, notes, and snippets.

@plusor
Created July 29, 2013 14:27
Show Gist options
  • Save plusor/6104678 to your computer and use it in GitHub Desktop.
Save plusor/6104678 to your computer and use it in GitHub Desktop.
Minitest Assertions

Assertion Example

assert              assert                            @subject.any?     ,"empty subjects"
assert_block        assert_block                      { @subject.any? }
assert_empty        assert_empty                      @list
assert_equal        assert_equal                      2                 , @subject.size
assert_in_delta     assert_in_delta                   @subject.size     , 1                 ,1
assert_in_epsilon   assert_in_epsilon                 @subject.size     , 1                 , 1
assert_same         assert_same                       @subject          , @subject          , "It's the same object silly"
assert_operator     assert_operator                   @list.size        , :==               , 0
assert_includes     assert_includes                   @subject          , "skinny jeans"
assert_instance_of  assert_instance_of                Array             , @list
assert_kind_of      assert_kind_of                    Enumerable        , @list
assert_match        assert_match                      @subject.first    , /silly/
assert_nil          assert_nil                        @list.first
assert_output       assert_output("Size: 2")          { print "Size: #{@subject.size}"}
assert_raises       assert_raises(NoMethodError)      { @subject.foo }
assert_respond_to   assert_respond_to                 @subject          , :count
assert_send         assert_send                       [@subject, :values_at, 0]
assert_silent       assert_silent                     { "no stdout or stderr" }
assert_throws       assert_throws(:error,'is empty')  {throw :error if @subject.any?}

Minitest Matchers

Assertion Example

must_be                 list.size.must_be                                 :==, 0
must_be_close_to        subject.size.must_be_close_to                     1,1
must_be_empty           list.must_be_empty
must_be_instance_of     list.must_be_instance_of                          Array
must_be_kind_of         list.must_be_kind_of                              Enumerable
must_be_nil             list.first.must_be_nil
must_be_same_as         subject.must_be_same_as                           subject
must_be_silent          proc { "no stdout or stderr" }.must_be_silent
must_be_within_epsilon  subject.size.must_be_within_epsilon               1,1
must_equal              subject.size.must_equal                           2
must_include            subject.must_include                              "skinny jeans"
must_match              subject.first.must_match                          /silly/
must_output             proc { print "#{subject.size}!" }.must_output     "2!"
must_respond_to         subject.must_respond_to                           :count
must_raise              proc { subject.foo }.must_raise                   NoMethodError
must_send               subject.must_send                                 [subject, :values_at, 0]
must_throw              proc { throw :done if subject.any? }.must_throw   :done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment