and_that as a synonym for expects_that

2 views
Skip to first unread message

Eric Lefevre-Ardant

unread,
Nov 29, 2010, 10:41:49 AM11/29/10
to narrati...@googlegroups.com
I kinda remember a piece of code where and_that() was used instead of expects_that(). Could not find it. Maybe it never existed?

To be more clear, here is what I can write today:
    Then.the(quant)//
            .expects_that(the_number_of_equitycharts_for(FTSE, GBP, Hourly), equalTo(1))//
            .expects_that(the_number_of_barcharts_for(FTSE, GBP, Hourly), equalTo(1));

It would be nicer if I could write
    Then.the(quant)//
        .expects_that(the_number_of_equitycharts_for(FTSE, GBP, Hourly), equalTo(1))//
        .and_that(the_number_of_barcharts_for(FTSE, GBP, Hourly), equalTo(1));

One minor drawback I see is that it is slightly hard to refactor. If I want to check the 2nd assumption before the 1st one, I cannot just swap the last 2 lines. I must also change make sure that the order of expects_that() and and_that() is correct.

Thoughts?

Eric

Samir Talwar

unread,
Nov 30, 2010, 5:41:36 AM11/30/10
to narrative-users
There were two methods: `andAlso()` and `and_also_expects_that()`. We
removed them in version 1.0 because we were simplifying Then and the
method didn't exist in Given and When—we had the `and_the(user)`
methods in those, which are still there and now also exist in Then. If
there's demand for it, we'll put something similar back in and add it
to the others (if you have any ideas how best you'd like to see it
done, feel free to fork and send a pull request). We didn't want to
have too much in the way of helper methods to start with in 1.0, as
it's much easier to add stuff than remove it.

Scriptwriter—our upcoming web page generator for Narrative tests—may
also be a potential solution: you could write
`.expects_that(…).expects_that(…)` and Scriptwriter could display it
with "and" instead. However, this is only helpful if you plan on
viewing your tests in a web browser rather than in your IDE.

— Samir.

Eric Lefevre-Ardant

unread,
Nov 30, 2010, 6:57:47 AM11/30/10
to narrati...@googlegroups.com
Well, I don't think we (as developers) would use Scriptwriter. I see it mostly as a tool to show our tests to our users (a fairly marginal benefit, I might add).

I'd be interested to know if you think having and_that() methods as exact synonyms to expects_that() is a good idea or not.

Eric

Samir Talwar

unread,
Dec 1, 2010, 8:14:48 AM12/1/10
to narrati...@googlegroups.com
Personally, it doesn't particularly bother me—I find chaining calls to `expects_that` just as readable. However, I wouldn't be averse to it either. I don't often find myself reordering calls to the `expects_that` method, so I don't think there'd be much of a problem in that regard.

If no one has any objections, I'll put something into the trunk for version 1.1 when I find some free time. Gotta figure out similar aliases for Given and When too.

— Samir.

Douglas Squirrel

unread,
Dec 1, 2010, 8:21:28 AM12/1/10
to narrati...@googlegroups.com

Actually, Eric has already made a pull request for and_that (we like users who fork!!) I'll merge if no one objects (or beats me to it).

Douglas Squirrel

unread,
Dec 1, 2010, 12:58:27 PM12/1/10
to narrati...@googlegroups.com

Pull request now merged. Thanks Eric!

Reply all
Reply to author
Forward
0 new messages