Reputation: 825
I am using minitest for the first time and I am having trouble understanding how to write my first test method. Can anyone assist in helping me understand what I should be testing in the below Player method get_name?
class Player
def get_name(player)
puts `clear`
center("#{player}, whats your name bro/ladybro?")
@name = gets.chomp
until @name =~ /\A[[:alnum:]]+\z/
center("you can do a combination of alphanumeric characters")
@name = gets.chomp
end
end
end
This is what I have in my test file, I was thinking I am just suppose to test the regex to make sure it takes alpha and numeric characters.
class TestPlayer < Minitest::Test
def test_get_name
describe "get_name" do
it "should allow an input of alphanumeric characters" do
assert_match(/\A[[:alnum:]]+\z/, "test_string123")
end
end
end
end
but when I run the tests, nothing seems to happen, I would imagine I am suppose to have 1 assertion.
Run options: --seed 10135
# Running:
.
Finished in 0.001565s, 638.9776 runs/s, 0.0000 assertions/s.
1 runs, 0 assertions, 0 failures, 0 errors, 0 skips
can anyone assist in demonstrating how I should write a test for this scenario? thanks.
Upvotes: 0
Views: 301
Reputation: 18804
Minitest test may be described as follows (Assertion syntax):
Minitest::Test
.setup
will be called at the first; you can define objects that you may require in every test. Eg: Consider assigning an instance of the Player
object here in an instance variable in setup
method so that you can use it elsewhere in the test class.test_
; any other method can be used to reduce duplication of code but it won't be considered part of tests.Upvotes: 1