when do we use assert and asert_not in ruby on rails tests, what's the difference between the to? Example:
test 'email should not be too long' do
@user.email = 'a' * 244 '@example.com'
assert_not @user.valid?
end
test 'email validation should accept valid addresses' do
valid_addresses = %w[[email protected] [email protected] [email protected]
[email protected] alice [email protected]]
valid_addresses.each do |valid_address|
@user.email = valid_address
assert @user.valid?, "#{valid_address.inspect} should be valid"
end
end
CodePudding user response:
Use assert_not
when you expect the result to be false
.
https://apidock.com/rails/ActiveSupport/Testing/Assertions/assert_not
Use assert
when you expect the result to be true
.
https://docs.ruby-lang.org/en/2.1.0/Test/Unit/Assertions.html