Thanks to all of you who replied.
It looks like the most common pattern for this is to do the black-box
testing actually creating the data.
This is what I usually end-up doing. But it has always been smelling bad to
me.
In any case, so far there doesn't seem to be a better approach and I guess
I
Bikeshedding from a non-Rails developer here, but rather than seeing
if two items are sorted correctly, you could specify that one object
is treated as coming before another object
object1.should < object2
or
sorting(object1, object2).should eq -1
It might make it easier to read.
Andrew
On We
I agree with Paul and David. I would use strategy (2) with Machinist'd
data or stubs.
1. Set up two items, out of order.
2. Assert ordered(items) swaps them.
If you are concerned about further cases such as numerical sorting
versus string sorting, or edge cases, then put those in too, but
David's
On 14/08/2012, at 2:02 PM, Dmytrii Nagirniak wrote:
> I wonder what approaches you take to spec-ing ordering.
> Often the ordering doesn't matter much and I tend to skip that part.
>
> But when it is a feature and doesn't map directly to SQLs "ORDER BY" clause
> then it must be spec-ed.
> This
Given a high enough sample size, and a random insert order, (2) can be used
as a test with reasonable confidence.
It's not 100%, but it's close enough and better than the alternatives.
On Tue, Aug 14, 2012 at 2:02 PM, Dmytrii Nagirniak wrote:
> Hi all,
>
> I wonder what approaches you take to s
I think it comes down to where your test boundaries are.
If you're just testing your interaction with ActiveRecord's API, and relying on
its test suites to cover the rest, then checking `relation.order_values` sounds
like the way to go.
If you feel it's important to test the end-to-end behaviou
On 14 August 2012 14:04, Ryan Bigg wrote:
> You can do it without dropping back down to SQL. Just check
> `order_values` on the ActiveRecord::Relation object returned.
>
Good idea, thanks. But that would be pretty close to the option 1.
I would just do `query.order_values.should ...` instead of
You can do it without dropping back down to SQL. Just check `order_values` on
the ActiveRecord::Relation object returned.
On Tuesday, 14 August 2012 at 2:02 PM, Dmytrii Nagirniak wrote:
> Hi all,
>
> I wonder what approaches you take to spec-ing ordering.
> Often the ordering doesn't matter
Hi all,
I wonder what approaches you take to spec-ing ordering.
Often the ordering doesn't matter much and I tend to skip that part.
But when it is a feature and doesn't map directly to SQLs "ORDER BY" clause
then it must be spec-ed.
This is especially the case when a mix of DB sorting + memory s