Building up queries/Transactions in Gherkin Scenarios.

54 views
Skip to first unread message

mswinson

unread,
Feb 26, 2012, 12:07:23 AM2/26/12
to Cukes

Hi,

I want to write the following type of scenario, which if you picture
it behind the scenes
is building up a task which is then to be run before returning
results.

When I search for x
With a filter of x
And a filter of x
Then I receive results containing y


A number of problems:
1) the With keyword does'nt exist, but I read somewhere that Gherkin
supports aliasing, so this is
something I might look into.
2) If I'm building up a search request in this way, what I have is
that the first three steps
implicitly translate to one transaction behind the scenes (an HTTP
request). Is what I'm
testing at fault, or do I need to simple rephrase what I'm trying to
test.

e.g:

When I want to search for a list of 'x'
And I use a keyphrase of 'keyphrase'
And a filter of 'filter1'
And a filter of 'filter2'
And I submit my search to 'server'
Then I should receive results containing y

What would be going on in terms of implementation details, is that the
first 4 steps would
be building a query request ( e.g an HTTP query string ), and step 5
would essentially forward
the request to the search server.

This seems to work and read better, but I'm not sure if its the sort
of thing I should be doing with gherkin?

Mark








Richard Lawrence

unread,
Feb 26, 2012, 12:35:19 AM2/26/12
to cu...@googlegroups.com
How about:

When I search for X with filters:
| filter |
| Y |
| Z |

or, if the filter names are short:

When I search for X with filters Y, Z, and Q

Richard

> --
> You received this message because you are subscribed to the Google Groups "Cukes" group.
> To post to this group, send email to cu...@googlegroups.com (mailto:cu...@googlegroups.com).
> To unsubscribe from this group, send email to cukes+un...@googlegroups.com (mailto:cukes+un...@googlegroups.com).
> For more options, visit this group at http://groups.google.com/group/cukes?hl=en.

Andy Waite

unread,
Feb 26, 2012, 6:07:29 AM2/26/12
to Cukes


On Feb 26, 5:35 am, Richard Lawrence <rich...@humanizingwork.com>
wrote:
> How about:
>
> When I search for X with filters:
> | filter |
> | Y |
> | Z |
>
> or, if the filter names are short:

A little tip - if a table only has a single column, you can leave out
the header row and use table.raw.flatten to turn it into an array.

Andy

Andrew Premdas

unread,
Feb 26, 2012, 9:41:22 AM2/26/12
to cu...@googlegroups.com
Fundamentally gherkin is about expressing business needs, not about listing implementation details. What you should do is find a name for x with a filter of x and x. Then you can just have

When I search for foo
Then I should see results for foo

This is just so much easier to implement, and the feature has less noise. All the detail about the filters is delegated down to the step definitions, and ideally down to your actual source. For example if this was a Rails app you would use foo to define a scope and then have you search use the scope. Now instead of having the scope defined in two places (the text of your feature and you source) you are only using the definition in your code.

If you really want to assemble  something in gherkin then you can communicate between steps in a number of ways

1) Use a variable e.g @search
2) Put something in a database and then retrieve it using last in subsequent steps e.g. Search.last (this relies on the database being emptied between scenarios)
3) Identify the thing in the feature and then use the id to retrieve e.g. When I create a foo search,  And I add a filter to foo and then Search.find('foo') in subsequent steps

Variables can be very elegant, especially for feature text but their overuse can quickly cause chaos (their globals after all)
Using last is fine, until you add something else into the database by mistake e.g. using a related factory with a side effect
Using an identity is safest but uglifies your features

HTH

Andrew
 
 
 






--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To post to this group, send email to cu...@googlegroups.com.
To unsubscribe from this group, send email to cukes+un...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/cukes?hl=en.




--
------------------------
Andrew Premdas
Reply all
Reply to author
Forward
0 new messages