hello all, I have a requirement to trim a string to fit a specific width. This data is displayed under some table column, and need to fit the column width. Since I can''t tell the exact pixel in html. so we needn''t be too exact about the trimLength. I want to do something like trimString(String source, int hintColumnWidth), but can I Unit Test it?( since the requirement is vague here.) Also the requirement says that , when it trims, it should display full string as tooltip , and that becomes <span title=...> etc, and then can I UT it? Thanks. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 10/19/06, femto gary <femtowin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > hello all, I have a requirement to trim a string to fit > a specific width. This data is displayed under some table column, > and need to fit the column width. Since I can''t tell the exact pixel in > html. > so we needn''t be too exact about the trimLength. I want to do something > like > trimString(String source, int hintColumnWidth), but can I Unit Test it?( > since > the requirement is vague here.) > Also the requirement says that , when it trims, it should display full > string > as tooltip , and that becomes <span title=...> etc, and then can I UT it? > Thanks.trucate will trucate your text, but you will need a helper to do the rest. Something like def my_cell_value( a_string ) "<span title=''#{a_string}>#{truncate( a_string, 23 )}</span>" end in your helper file should do the job. Hope that helps --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks Daniel , I know the general code. What I want to know is about testing. Since the requirement isn''t very exact, so say, 3 columnWidthUnit = 1 strLengthUnit, so I write trim(str,columnWidthUnit/3) for that. so if the method is trimString(source, hintColumnWidth), Then in test, I just test trimString("helloworld", 3) produces "h...", Am I correct? And about tooltip, I test result str equals to "<span title=''helloworld''>h...</span>", right? So If I will put in html other attributes, like <span id=... title=...>, then I use regex to test it? Right? On 10/19/06, Daniel N <has.sox-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > > On 10/19/06, femto gary <femtowin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > hello all, I have a requirement to trim a string to fit > > a specific width. This data is displayed under some table column, > > and need to fit the column width. Since I can''t tell the exact pixel in > html. > > so we needn''t be too exact about the trimLength. I want to do something > like > > trimString(String source, int hintColumnWidth), but can I Unit Test it?( > since > > the requirement is vague here.) > > Also the requirement says that , when it trims, it should display full > string > > as tooltip , and that becomes <span title=...> etc, and then can I UT it? > > Thanks. > > trucate will trucate your text, but you will need a helper to do the rest. > Something like > > def my_cell_value( a_string ) > "<span title=''#{a_string}>#{truncate( a_string, 23 )}</span>" > end > > in your helper file should do the job. > > Hope that helps > > > > > >-- Best Regards femto http://femto.blogdriver.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 -~----------~----~----~----~------~----~------~--~---
On 10/19/06, femto gary <femtowin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Thanks Daniel , > I know the general code. > What I want to know is about testing. > Since the requirement isn''t very exact, > so say, 3 columnWidthUnit = 1 strLengthUnit, > so I write trim(str,columnWidthUnit/3) for that. > so if the method is trimString(source, hintColumnWidth), > Then in test, I just test trimString("helloworld", 3) produces "h...", > Am I correct? > And about tooltip, I test result str equals to "<span > title=''helloworld''>h...</span>", > right? So If I will put in html other attributes, like <span id=... > title=...>, > then I use regex to test it? Right?Sorri . Seems I misunderstood. I wouldn''t use a regex directly for this. You can use something like assert_tag or even better HPricott http://api.rubyonrails.org/classes/Test/Unit/Assertions.html#M000970 Luck Redpath has a small writeup on using HPricott to test views. It''s here http://www.lukeredpath.co.uk/2006/7/7/testing-your-rails-views-with-hpricot I hope that''s more along the lines of what your after. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi Daniel, that looks interesting.I''ll check it up. I''d thought about selenium, but I feel in this small requirement using selenium to test that would be an overkill and too much effort to set up. Thanks for the hint. On 10/19/06, Daniel N <has.sox-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On 10/19/06, femto gary <femtowin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Thanks Daniel , > > I know the general code. > > What I want to know is about testing. > > Since the requirement isn''t very exact, > > so say, 3 columnWidthUnit = 1 strLengthUnit, > > so I write trim(str,columnWidthUnit/3) for that. > > so if the method is trimString(source, hintColumnWidth), > > Then in test, I just test trimString("helloworld", 3) produces "h...", > > Am I correct? > > And about tooltip, I test result str equals to "<span > > title=''helloworld''>h...</span>", > > right? So If I will put in html other attributes, like <span id=... > title=...>, > > then I use regex to test it? Right? > > Sorri . Seems I misunderstood. > > I wouldn''t use a regex directly for this. You can use something like > assert_tag or even better HPricott > > http://api.rubyonrails.org/classes/Test/Unit/Assertions.html#M000970 > > Luck Redpath has a small writeup on using HPricott to test views. It''s here > > http://www.lukeredpath.co.uk/2006/7/7/testing-your-rails-views-with-hpricot > > I hope that''s more along the lines of what your after. > > > > > >-- Best Regards femto http://femto.blogdriver.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 -~----------~----~----~----~------~----~------~--~---