You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.1 KiB
60 lines
1.1 KiB
require 'minitest/autorun'
|
|
require './typo_bomb.rb'
|
|
|
|
class TypoBombTest < Minitest::Test
|
|
|
|
def self.test_order
|
|
:sorted
|
|
end
|
|
|
|
def test_bomb
|
|
bomb = TypoBomb.new
|
|
val = bomb.get_stuf
|
|
|
|
assert_equal val, 'My method is working as expected'
|
|
|
|
assert_raises NoMethodError do
|
|
bomb.get_stuff
|
|
end
|
|
end
|
|
|
|
def test_bomb_from_other_instance
|
|
bomb = TypoBomb.new
|
|
|
|
# but where is the typo???
|
|
# hint: check the previous unit test.
|
|
#
|
|
# want to break it even more?
|
|
# remove the test_order declaration at the top
|
|
# or change :sorted to :random
|
|
# now this test will sometimes pass and sometimes fail ;)
|
|
assert_raises NoMethodError do
|
|
bomb.get_stuff
|
|
end
|
|
end
|
|
|
|
def test_extended_classes
|
|
inh = InheritedBomb.new
|
|
val = inh.get_favorite_numb
|
|
|
|
assert_equal val, 5
|
|
|
|
assert_raises NoMethodError do
|
|
inh.get_favorite_number
|
|
end
|
|
end
|
|
|
|
def test_extended_classes_with_arguments
|
|
calc = CalculatorBomb.new
|
|
|
|
val = calc.ad(4, 5)
|
|
val2 = calc.subtract(5, 4)
|
|
|
|
assert_equal val, 9
|
|
assert_equal val2, 1
|
|
|
|
assert_raises NoMethodError do
|
|
calc.add(1, 0)
|
|
end
|
|
end
|
|
end
|
|
|