I placed this in my ~/bin folder so that I could run it whenever I need a quick refresher on the available assertions. It will automatically include changes as minitest gets updated over time and versions.
#!/usr/bin/env ruby
require 'test/unit'
require 'minitest/spec'
# Reasonable default of 3 columns
@columns = 3
puts "== Spec Style"
def columnize(method)
@column_count ||= 1
print "#{method}".ljust(25)
if @column_count == @columns
puts
@column_count = 0
end
@column_count += 1
end
MiniTest::Spec.methods.sort.each do |method|
if method.to_s =~ /wont/ or method.to_s =~ /must/
columnize(method)
end
end
puts "\n\n== Test Style"
column_count = 1
MiniTest::Assertions.instance_methods.sort.each do |method|
if method =~ /assert/ or method.to_s =~ /refute/
columnize(method)
end
end
Currently the list shows:
== Spec Style
must_be must_be_close_to must_be_empty
must_be_instance_of must_be_kind_of must_be_nil
must_be_same_as must_be_silent must_be_within_delta
must_be_within_epsilon must_equal must_include
must_match must_output must_raise
must_respond_to must_send must_throw
wont_be wont_be_close_to wont_be_empty
wont_be_instance_of wont_be_kind_of wont_be_nil
wont_be_same_as wont_be_within_delta wont_be_within_epsilon
wont_equal wont_include wont_match
wont_respond_to
== Test Style
_assertions _assertions=
assert assert_block 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_raises assert_respond_to
assert_same assert_send assert_silent
assert_throws refute 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_respond_to refute_same
I placed this in my ~/bin folder so that I could run it whenever I need a quick refresher on the available assertions. It will automatically include changes as minitest gets updated over time and versions.