In Agile Web Development with Rails, the following statement is given: assert_equal "has already been taken", product.errors[:title].join(''; '') My question is: Why is the join(...) needed and what exactly does it do here? If it does what I assume, join an array of strings and use "; " as the separator, then I wonder how the assert_equal statement could ever evaluate to true as the first parameter is a static string without "; " Can you shed some light for me? -- 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.
On Nov 14, 9:48 pm, 24z <r...-3vQWZ2fCnPIwofDVIiI1Aw@public.gmane.org> wrote:> In Agile Web Development with Rails, the following statement is given: > > assert_equal "has already been taken", product.errors[:title].join(''; > '') > > My question is: Why is the join(...) needed and what exactly does it > do here? > > If it does what I assume, join an array of strings and use "; " as the > separator, then I wonder how the assert_equal statement could ever > evaluate to true as the first parameter is a static string without "; > " > > Can you shed some light for me?If there is only supposed to be one error on title (ie the errors[:title] contains a single string) then join will just return that string. Hard to say without knowing the wider context, but this seems a fairly succinct way of saying that there should only be one error for the title attribute and that it should be the one that comes from the uniqueness validation. Fred -- 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.
24z wrote in post #961471:> In Agile Web Development with Rails, the following statement is given: > > assert_equal "has already been taken", product.errors[:title].join(''; > '') > > My question is: Why is the join(...) needed and what exactly does it > do here? > > If it does what I assume, join an array of strings and use "; " as the > separator, then I wonder how the assert_equal statement could ever > evaluate to true as the first parameter is a static string without "; > " >That seems like a strangely written assertion. Obviously, the only way it could return true is if product.errors[:title] has only one element.> Can you shed some light for me?Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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.
Seemingly Similar Threads
- Difference between rake test:units and individually running ruby -I test test/unit/something_test.rb ?
- configure question and passenger
- testing chapter: agile web dev withrails
- Function Testing Reloading Fixtures before assertion
- assert_equal - problems returning value from controller