Forum: RSpec Cucumber feature checking sort order of list

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
8a2de74362a8ee5f9c5e86b1ba0b1640?d=identicon&s=25 Joaquin Rivera Padron (Guest)
on 2008-11-12 15:38
(Received via mailing 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
C4228db54c76deba18a92bf7560ea493?d=identicon&s=25 Peter Ehrenberg (Guest)
on 2008-11-12 16:06
(Received via mailing list)
2008/11/12 Joaquin Rivera Padron <joahking@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?
8a2de74362a8ee5f9c5e86b1ba0b1640?d=identicon&s=25 Joaquin Rivera Padron (Guest)
on 2008-11-12 16:32
(Received via mailing list)
> 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
C4228db54c76deba18a92bf7560ea493?d=identicon&s=25 Peter Ehrenberg (Guest)
on 2008-11-12 16:47
(Received via mailing list)
2008/11/12 Joaquin Rivera Padron <joahking@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
Cdf378de2284d8acf137122e541caa28?d=identicon&s=25 Matt Wynne (mattwynne)
on 2008-11-12 16:56
(Received via mailing 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
8a2de74362a8ee5f9c5e86b1ba0b1640?d=identicon&s=25 Joaquin Rivera Padron (Guest)
on 2008-11-12 17:04
(Received via mailing 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}/
> end


yep, this one looks better to me
thanks Matt

jk
Cdf378de2284d8acf137122e541caa28?d=identicon&s=25 Matt Wynne (mattwynne)
on 2008-11-12 17:12
(Received via mailing list)
On 12 Nov 2008, at 16:03, Joaquin Rivera Padron wrote:
> end
>
> yep, this one looks better to me
> thanks Matt

Might 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
48641c4be1fbe167929fb16c9fd94990?d=identicon&s=25 Mark Wilden (Guest)
on 2008-11-12 18:44
(Received via mailing list)
On Wed, Nov 12, 2008 at 7:55 AM, Matt Wynne <matt@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.

///ark
Cdf378de2284d8acf137122e541caa28?d=identicon&s=25 Matt Wynne (mattwynne)
on 2008-11-12 18:54
(Received via mailing list)
On 12 Nov 2008, at 17:43, Mark Wilden 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. :) 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
C4228db54c76deba18a92bf7560ea493?d=identicon&s=25 Peter Ehrenberg (Guest)
on 2008-11-12 20:06
(Received via mailing list)
Mutch better as mine!
This topic is locked and can not be replied to.