Joaquin Rivera Padron
2008-Nov-12 14:38 UTC
[rspec-users] Cucumber feature checking sort order of list
hi there, I would like to assure in my scenario that the list shown is in the correct order (e.g. ASC or DESC). I can spec that but I feel it would be more client-oriented if I could do it in the feature... any ideas? thanks, joahking -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20081112/a5b214d4/attachment.html>
Peter Ehrenberg
2008-Nov-12 15:05 UTC
[rspec-users] Cucumber feature checking sort order of list
2008/11/12 Joaquin Rivera Padron <joahking at gmail.com>:> I would like to assure in my scenario that the list shown is in the correct > order (e.g. ASC or DESC). > > I can spec that but I feel it would be more client-oriented if I could do it > in the feature... any ideas?You ask how to implement such a step? I''ve done this by using Hpricot - fetching the item-lines from the result into an array and checking this for the right order. Not very nice. Any better ideas?
Joaquin Rivera Padron
2008-Nov-12 15:31 UTC
[rspec-users] Cucumber feature checking sort order of list
> You ask how to implement such a step?yes> I''ve done this by using Hpricot - fetching the item-lines from the resultinto> an array and checking this for the right order.thanks Peter, seems I will give that a try, though I like you do not like very much joaquin -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20081112/b2cfddb4/attachment.html>
Peter Ehrenberg
2008-Nov-12 15:47 UTC
[rspec-users] Cucumber feature checking sort order of list
2008/11/12 Joaquin Rivera Padron <joahking at gmail.com>:>> [...] > thanks Peter, seems I will give that a try, though I like you do not like > very muchThis is my code. Maybe it helps: Then /the title are in alphabetic order/ do # FIXME: Ugly titles = [] doc = Hpricot(response.body) (doc/"tr/td[1]/*/text()").each do |e| titles << e.to_s end titles.should == titles.sort end
Matt Wynne
2008-Nov-12 15:55 UTC
[rspec-users] Cucumber feature checking sort order of list
How about something more like
Given there are two items in a list: "Zulu and Abba"
And I have sorted the list alphabetically
Then "Abba" should appear before "Zulu"
Then /"(.*)" should appear before "(.*)"/ do |first_example,
second_example|
response.body.should =~ /#{first_example}.*#{second_example}/
end
On 12 Nov 2008, at 15:47, Peter Ehrenberg wrote:
> 2008/11/12 Joaquin Rivera Padron <joahking at gmail.com>:
>>> [...]
>> thanks Peter, seems I will give that a try, though I like you do
>> not like
>> very much
>
> This is my code. Maybe it helps:
>
> Then /the title are in alphabetic order/ do
> # FIXME: Ugly
> titles = []
> doc = Hpricot(response.body)
> (doc/"tr/td[1]/*/text()").each do |e|
> titles << e.to_s
> end
> titles.should == titles.sort
> end
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
Joaquin Rivera Padron
2008-Nov-12 16:03 UTC
[rspec-users] Cucumber feature checking sort order of list
> Matt Wynne:> How about something more like > > Given there are two items in a list: "Zulu and Abba" > And I have sorted the list alphabetically > Then "Abba" should appear before "Zulu" > > Then /"(.*)" should appear before "(.*)"/ do |first_example, > second_example| > response.body.should =~ /#{first_example}.*#{second_example}/ > endyep, this one looks better to me thanks Matt jk -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20081112/f4a182ca/attachment.html>
Matt Wynne
2008-Nov-12 16:12 UTC
[rspec-users] Cucumber feature checking sort order of list
On 12 Nov 2008, at 16:03, Joaquin Rivera Padron wrote:> > Matt Wynne: > How about something more like > > Given there are two items in a list: "Zulu and Abba" > And I have sorted the list alphabetically > Then "Abba" should appear before "Zulu" > > Then /"(.*)" should appear before "(.*)"/ do |first_example, > second_example| > response.body.should =~ /#{first_example}.*#{second_example}/ > end > > yep, this one looks better to me > thanks MattMight not compile - I wrote it in my email client ;) The looser the better with these, IMO. Just enough to catch your code being broken, not a bit more. cheers, Matt
Mark Wilden
2008-Nov-12 17:43 UTC
[rspec-users] Cucumber feature checking sort order of list
On Wed, Nov 12, 2008 at 7:55 AM, Matt Wynne <matt at mattwynne.net> wrote:> How about something more like > > Given there are two items in a list: "Zulu and Abba" > And I have sorted the list alphabetically > Then "Abba" should appear before "Zulu" > > Then /"(.*)" should appear before "(.*)"/ do |first_example, > second_example| > response.body.should =~ /#{first_example}.*#{second_example}/ > endThe trouble with that is that you still have a 50-50 chance that your code is broken. :) Testing sorting is always problematic. Given a particular data set, other factors may be producing the "right" order (sorting on a different attribute, randomization). I usually use three items, and realize that it''s not definitive. ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20081112/f65d6793/attachment.html>
Matt Wynne
2008-Nov-12 17:53 UTC
[rspec-users] Cucumber feature checking sort order of list
On 12 Nov 2008, at 17:43, Mark Wilden wrote:> On Wed, Nov 12, 2008 at 7:55 AM, Matt Wynne <matt at mattwynne.net> > wrote: > How about something more like > > Given there are two items in a list: "Zulu and Abba" > And I have sorted the list alphabetically > Then "Abba" should appear before "Zulu" > > Then /"(.*)" should appear before "(.*)"/ do |first_example, > second_example| > response.body.should =~ /#{first_example}.*#{second_example}/ > end > > The trouble with that is that you still have a 50-50 chance that > your code is broken. :) Testing sorting is always problematic. Given > a particular data set, other factors may be producing the "right" > order (sorting on a different attribute, randomization). I usually > use three items, and realize that it''s not definitive.Sure, but balance it with another scenario that sorts it the other way, and you''d have to be pretty unlucky to get a false positive from both at the same time. :) cheers, Matt