An easier way to test a valid username
Your regex looks wrong, see my link below.

If your functional requirement is that usernames match a certain regex, then your tests should reflect that. It is wrong to test a bunch of edge cases that a generic regex catches.

See this. All you need in your test is to do:

username_regex = /^[a-z0-9][a-z0-9-]*$/i
passing_usernames = ['passing','pAsSing-PASS-'.....]
failing_usernames = ['-failing','failing#'....]
passing_usernames.each { |username| assert_match username_regex, username}
failing_usernames.each { |username| assert_no_match username_regex, username }


If you're getting your username from somewhere else then just plug that in the same way.