im trying since a few days with unit test.
my problem is, i have write a test for 7 validates_presence_of and its
ok.
then i have write 2 validates_uniqueness_of and its ok.
then i have write 1 test for validates_format_of :postcode, :with =>
/^\d{5}$/
its also ok.
if i have write a test for validates_format_of :street, :with =>
/^([[:alpha:]]+\s)+\d*$/ like this:
def test_street_format
ok = ["on the road 7", "my street"]
notok = ["8ue kd9", "die 8.straße 9"]
ok.each do |name|
sp = Me.new(:name => "MyString", :contact_person => "My person",
:location => "Mybla", :postcode => "12345", :street => name, :password
=> "MyStkdju", :email => "[email protected]")
assert sp.valid? #, sp.errors.full_messages
notok.each do |name|
sp = Me.new(:name => "MyString", :contact_person => "My person",
:location => "Mybla", :postcode => "12345", :street => name, :password
=> "MyStkdju", :email => "[email protected]")
assert !sp.valid?
end
end
end
i became failures like this
1) Failure:
test_postcode_format(MeTest):
<false> is not true.
2) Failure:
test_street_format(MeTest):
<false> is not true.
Finished in 0,139 seconds.
8 tests, 2 failures, 0 errors
/^([[:alpha:]]+\s)+\d*$/ like this:
Looks to me like this regexp means that “my street” cannot match
(since you’ve said that each of your words must be finished by a space
(so i would expect "my street " to pass)).
Other than that you need to do some detective work: what line is it
failing on ? with what input ? which validations are failing etc.
then i have write 1 test for validates_format_of :postcode, :with =>
/^\d{5}$/
its also ok.
Looks to me like this regexp means that “my street” cannot match
(since you’ve said that each of your words must be finished by a space
(so i would expect "my street " to pass)).
Other than that you need to do some detective work: what line is it
failing on ? with what input ? which validations are failing etc.
Next advice: Comment out every test that fails, then write a test like
this:
assert_match ‘12348’, /^\d{5}/
If you have trouble with a high-level test, scratch it and write a
low-level
one; one that only targets the details. In this case, you are not even
testing
the actual validator; you are using the testing to learn which regexps
work.
/^([[:alpha:]]+\s)+\d*$/ like this:
Looks to me like this regexp means that “my street” cannot match
(since you’ve said that each of your words must be finished by a space
(so i would expect "my street " to pass)).
Other than that you need to do some detective work: what line is it
failing on ? with what input ? which validations are failing etc.
Fred
hello,
my test for validates_format_of :street, :with =>
/^[[:alpha:]]+\s{1}[[:alpha:]])\d*$/ is this: