Ezequiel Schwartzman
2011-Aug-28 17:29 UTC
Is a bad practice to do this while testing with Rspec?
I''m testing the validation of emails so I did the following: it ''should only allow domains names with numbers, letters, dots or dashes'' do (%-\\|!"#$\%&/()=?¡;,:{}+''<>°+*[]"¬~^@áéíóú´`_ -).each_char do |c| Factory.build(:user, :email => "zequez@gm#{c}ail.com").should_not be_valid end end Also this: [''1@1.com'', ''1-a-1-8yCJrxgw/Js@public.gmane.org'', ''zequez..--pWgKQ6/u3Fg@public.gmane.org'', ''z_e_q_u_e_z-p5J8OdVfRrihoOLXe+sDGSl/zTl+IsRl@public.gmane.org'', ''zambuche-p5J8OdVfRrihoOLXe+sDGSl/zTl+IsRl@public.gmane.org'', ''zEzEqZ-3AK8maZG0SA@public.gmane.org'', ''zzzzzzzzzzz-fqskXWjLZVE@public.gmane.org'', ''z@q.z'', ''yo-fnHTXw5TXazQT0dZR+AlfA@public.gmane.org'', ''ca..--__ca..--__ca..--__a-fnHTXw5TXazQT0dZR+AlfA@public.gmane.org''].each do |email| it "should allow #{email} as a valid email" do Factory.build(:user, :email => email).should be_valid end end And many similar things... Is that bad? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
David Kahn
2011-Aug-28 17:35 UTC
Re: Is a bad practice to do this while testing with Rspec?
On Sun, Aug 28, 2011 at 10:29 AM, Ezequiel Schwartzman <lists-fsXkhYbjdPsM1dTnIXmMWg@public.gmane.orgm> wrote:> I''m testing the validation of emails so I did the following: > > it ''should only allow domains names with numbers, letters, dots or > dashes'' do > (%-\\|!"#$\%&/()=?¡;,:{}+''<>°+*[]"¬~^@áéíóú´`_ -).each_char do > |c| > Factory.build(:user, :email => > "zequez@gm#{c}ail.com").should_not be_valid > end > end > > Also this: > > [''1@1.com'', > ''1-a-1-8yCJrxgw/Js@public.gmane.org'', > ''zequez..--pWgKQ6/u3Fg@public.gmane.org'', > ''z_e_q_u_e_z-p5J8OdVfRrihoOLXe+sDGSl/zTl+IsRl@public.gmane.org'', > ''zambuche-p5J8OdVfRrihoOLXe+sDGSl/zTl+IsRl@public.gmane.org'', > ''zEzEqZ-3AK8maZG0SA@public.gmane.org'', > ''zzzzzzzzzzz-fqskXWjLZVE@public.gmane.org'', > ''z@q.z'', > ''yo-fnHTXw5TXazQT0dZR+AlfA@public.gmane.org'', > ''ca..--__ca..--__ca..--__a-fnHTXw5TXazQT0dZR+AlfA@public.gmane.org''].each do |email| > it "should allow #{email} as a valid email" do > Factory.build(:user, :email => email).should be_valid > end > end > > And many similar things... > > Is that bad? >In my book this is fine.... you have a list of specific examples and it is clear what you are doing. I might go further and make sure that in fact it is the email which is valid/invalid vs just checking the model (at least in the case if you are checking what should be invalid data) as another field could be the invalid one. I also like shoulda as you get helpers like: it { should allow_value(''david.n_kahn-Re5JQEeQqe8GXtTpemXPTA@public.gmane.org'').for(:email) } it { should_not allow_value(''david nathan kahn at gmail dot com'').for(:email) }> > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
Ezequiel Schwartzman
2011-Aug-28 17:59 UTC
Re: Is a bad practice to do this while testing with Rspec?
David K. wrote in post #1018921:> On Sun, Aug 28, 2011 at 10:29 AM, Ezequiel Schwartzman > <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org > > In my book this is fine.... you have a list of specific examples and it > is > clear what you are doing. I might go further and make sure that in fact > it > is the email which is valid/invalid vs just checking the model (at least > in > the case if you are checking what should be invalid data) as another > field > could be the invalid one. > > I also like shoulda as you get helpers like: > > it { should allow_value(''david.n_kahn-Re5JQEeQqe8GXtTpemXPTA@public.gmane.org'').for(:email) } > it { should_not allow_value(''david nathan kahn at gmail dot > com'').for(:email) }Thanks! I''m looking into shoulda now, it seems very useful! ^^ -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.