Hello, 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: [code] 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 => "MyStri-nzEtHANgo3M@public.gmane.org") 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 => "MyStri-nzEtHANgo3M@public.gmane.org") assert !sp.valid? end end end[/code] i became failures like this [code] 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 [/code] I don''t know whats wrong. please help. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Feb 17, 11:01 pm, Hello Guy <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hello, > > 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: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> [code] 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 => "MyS...-nzEtHANgo3M@public.gmane.org") > 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 => "MyS...-nzEtHANgo3M@public.gmane.org") > assert !sp.valid? > end > end > end[/code] > i became failures like this > [code] > 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 > [/code] > I don''t know whats wrong. > please help. > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
>> 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. -- Phlip http://broadcast.oreilly.com/2009/02/merb-mind-maps.html --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> On Feb 17, 11:01�pm, Hello Guy <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: >> /^([[: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. > > Fredhello, my test for validates_format_of :street, :with => /^[[:alpha:]]+\s{1}*[[:alpha:]])*\d*$/ is this: def test_street_format ok = ["on road 7", "yourstreet"] 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, :email => "MyStri-nzEtHANgo3M@public.gmane.org") 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, :email => "MyStri-nzEtHANgo3M@public.gmane.org") assert !sp.valid? end end end is my test not ok? i hope someone can help me please -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hello Guy wrote:> my test for validates_format_of :street, :with => > /^[[:alpha:]]+\s{1}*[[:alpha:]])*\d*$/ is this:> assert !sp.valid? > > is my test not ok?Did you also write a simpler test with only the rexexps and their targets in it? If a test that starts too far from your tested code is hard to work with, that is a sign you need more support from a lower-level test. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Phlip wrote:> Did you also write a simpler test with only the rexexps and their > targets in it? > > If a test that starts too far from your tested code is hard to work > with, that > is a sign you need more support from a lower-level test.Hello, my English isnt so good, sorry. I dont understand everything you wrote. can you give me an example for a simpler test for my situation? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hello Guy wrote:> my English isnt so good, sorry. I dont understand everything you wrote. > can you give me an example for a simpler test for my situation?in your model: VALIDATE = /@#$%^/ validates_format_of :snoo, VALIDATE in the test: def test_validate assert_match Model::VALIDATE, ''something'' end That''s all. Don''t build everything just to test the Regexp - just test it directly! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Phlip wrote:> Hello Guy wrote: > >> my English isnt so good, sorry. I dont understand everything you wrote. >> can you give me an example for a simpler test for my situation? > > in your model: > > VALIDATE = /@#$%^/ > validates_format_of :snoo, VALIDATE > > in the test: > > def test_validate > assert_match Model::VALIDATE, ''something'' > end > > That''s all. Don''t build everything just to test the Regexp - just test > it directly!ok thank you. i try this: in model: validates_format_of :street, :with => /^[[:alpha:]]+\s{1}*[[:alpha:]])*\d*$/ in test: def test_street_try assert_match(/^[[:alpha:]]+\s{1}*[[:alpha:]])*\d*$/, ''The Road 9'') end but i become this: Finished in 0,0 seconds. 0 tests, 0 failures, 0 errors whats wrong now? i dont know -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hello Guy wrote:> ok thank you. i try this: > in model: > validates_format_of :street, :with => > /^[[:alpha:]]+\s{1}*[[:alpha:]])*\d*$/ > > in test: > def test_street_try > assert_match(/^[[:alpha:]]+\s{1}*[[:alpha:]])*\d*$/, ''The Road 9'') > endThe // regexp in the validation should be the same one passed to the test. That''s so when you change the validation, the test will still cover it. That''s why I suggested putting the regexp into a constant.> > but i become this: > Finished in 0,0 seconds. > 0 tests, 0 failures, 0 errorsYou are not running any tests, because your assertion should have counted. Try with this: assert false in a test. If your tests don''t break, then you are not running them! -- Phlip --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---