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

2008/11/12 Joaquin Rivera P. [email protected]:

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?

You ask how to implement such a step?
yes

I’ve done this by using Hpricot - fetching the item-lines from the result
into
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

2008/11/12 Joaquin Rivera P. [email protected]:

[…]
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

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

Matt W.:

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 Matt

jk

On 12 Nov 2008, at 16:03, Joaquin Rivera P. wrote:

end

yep, this one looks better to me
thanks Matt

Might not compile - I wrote it in my email client :wink:

The looser the better with these, IMO. Just enough to catch your code
being broken, not a bit more.

cheers,
Matt

On Wed, Nov 12, 2008 at 7:55 AM, Matt W. [email protected] 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. :slight_smile: 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

On 12 Nov 2008, at 17:43, Mark W. wrote:

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. :slight_smile: 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.

:slight_smile:

cheers,
Matt

Mutch better as mine!