Hi All, I recently started using RoR and love it! I''m currently creating some unit tests and found this line in the scaffolding for a controller test: assert assigns(:users) What does it mean? I know what assert does but couldn''t find any documentation on the function assigns. Thanks for your help! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
dparkmit wrote:> I recently started using RoR and love it! I''m currently creating some > unit testsRemember to alternate _frequently_ between testing and coding, to see what your new code is doing!> and found this line in the scaffolding for a controller > test: assert assigns(:users) > > What does it mean? I know what assert does but couldn''t find any > documentation on the function assigns.Me neither - I learned it after joining a team already doing Rails projects. It means a controller said @users = something. You can fetch out any new controller instance variable with assigns(). I would also use assert_select() or assert_xpath() to parse the rendered HTML and find evidence the controller''s data appeared there. Just because a controller assigned something doesn''t mean the user can see it! -- Phlip http://www.oreilly.com/catalog/9780596510657/ ^ assert_xpath http://tinyurl.com/23tlu5 <-- assert_raise_message --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
thanks for the help! On Jul 26, 7:32 am, Phlip <phlip2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> dparkmit wrote: > > I recently started using RoR and love it! I''m currently creating some > > unit tests > > Remember to alternate _frequently_ between testing and coding, to see > what your new code is doing! > > > and found this line in the scaffolding for a controller > > test: assert assigns(:users) > > > What does it mean? I know what assert does but couldn''t find any > > documentation on the function assigns. > > Me neither - I learned it after joining a team already doing Rails projects. > > It means a controller said @users = something. You can fetch out any > new controller instance variable with assigns(). > > I would also use assert_select() or assert_xpath() to parse the > rendered HTML and find evidence the controller''s data appeared there. > Just because a controller assigned something doesn''t mean the user can > see it! > > -- > Phlip > http://www.oreilly.com/catalog/9780596510657/ > ^ assert_xpath > http://tinyurl.com/23tlu5 <-- assert_raise_message--~--~---------~--~----~------------~-------~--~----~ 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:> dparkmit wrote: > >> I recently started using RoR and love it! I''m currently creating some >> unit tests > > Remember to alternate _frequently_ between testing and coding, to see > what your new code is doing! > >> and found this line in the scaffolding for a controller >> test: assert assigns(:users) >> >> What does it mean? I know what assert does but couldn''t find any >> documentation on the function assigns. > > Me neither - I learned it after joining a team already doing Rails > projects. > > It means a controller said @users = something. You can fetch out any > new controller instance variable with assigns(). > > I would also use assert_select() or assert_xpath() to parse the > rendered HTML and find evidence the controller''s data appeared there. > Just because a controller assigned something doesn''t mean the user can > see it!By the way, it''s better to say: assert_not_nil assigns(:users) The #assert method test if a value is a true value (not false or nil). It''s a bit vague for testing whether @users is not nil. Someone should fix those scaffold tests, they confuse everyone. -- Josh Susser http://blog.hasmanythrough.com -- 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 -~----------~----~----~----~------~----~------~--~---
Josh Susser wrote:> By the way, it''s better to say: assert_not_nil assigns(:users)Next, it''s better to lock down the exact list of users (check my syntax): assert_equal %w(Alice Bob Carl), assigns(:users).map(&:login)> The #assert method test if a value is a true value (not false or nil). > It''s a bit vague for testing whether @users is not nil. Someone should > fix those scaffold tests, they confuse everyone.Just don''t do what I did. (-; -- Phlip http://www.oreilly.com/catalog/9780596510657/ ^ assert_xpath http://tinyurl.com/23tlu5 <-- assert_raise_message --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---