BDD, behat, gherking language … and more

I will just paste some chat logs with everzet. This happened year or two ago.

Here is nice place to say “Hey, everzet, thanks for the time :)”

It’s about

(02:17:55 PM) po_taka-work: i haave 2 links:
(02:18:28 PM) po_taka-work: <a href=”/thumbs.php?act=edit” id=””>Edit thumbs</a>
(02:18:28 PM) po_taka-work: <a href=”users.php?act=edit&login_id=5″>Edit</a>
(02:18:48 PM) po_taka-work: When i do {Then I follow “Edit”} it click 1st link
(02:18:56 PM) po_taka-work: why ? it should click 2nd
(02:22:25 PM) everzet: it uses partial match
(02:22:30 PM) everzet: so it finds both
(02:22:34 PM) everzet: but clicks on first one
(02:23:44 PM) everzet: you can create your own step definition in this case, which will click proper link
(02:23:56 PM) everzet: but instead, i would propose
(02:24:03 PM) everzet: to pause and think a little
(02:24:21 PM) everzet: what you have here is a UX problem
(02:24:47 PM) everzet: you have one specific edit link and one unspecific
(02:24:59 PM) everzet: so this could be an opportunity to fix it
(02:25:13 PM) everzet: yes, Behat helps you with that too
(02:25:17 PM) everzet: 🙂
(02:25:21 PM) po_taka-work: ok, tnx 🙂
(02:25:34 PM) po_taka-work: one more question, i have fields for date
(02:25:48 PM) po_taka-work: but date should be relative, eg tomorrow, yesterday etc…
(02:26:13 PM) po_taka-work: so i use beforeScneario hook to change text in Steps with proper date
(02:26:30 PM) everzet: DON’T use hooks to change steps
(02:26:36 PM) po_taka-work: why ?
(02:26:39 PM) everzet: DON’T change steps in runtime
(02:26:56 PM) everzet: cuz it could lead to strange problems
(02:27:45 PM) everzet: so, show me your step in feature
(02:28:00 PM) po_taka-work: i need dates 🙁 and dates like ‘tomorrow’, ‘yesterday’, ‘after 2 dats’
(02:28:00 PM) po_taka-work: if u dont change steps i should write code for every case
(02:28:26 PM) po_taka-work: now its
(02:28:26 PM) po_taka-work: Then I fill in “appointment_date” with “{?:date, +2 day, d.m.Y}”
(02:28:35 PM) po_taka-work: Then I fill in “appointment_date” with “{? : date, +2 day, d.m.Y}”
(02:28:47 PM) everzet: you see
(02:28:54 PM) po_taka-work: {? }  is my keyword for variable 🙂
(02:28:55 PM) everzet: you obviously have problem here
(02:29:09 PM) everzet: your steps are too technical
(02:29:30 PM) everzet: Shouldn’t it be
(02:30:09 PM) everzet: Then I set appointment date to tomorrow
(02:30:10 PM) everzet: ?
(02:30:21 PM) everzet: or
(02:30:33 PM) everzet: Then I set an appointment date to yesterday
(02:30:35 PM) everzet: or
(02:30:52 PM) everzet: Then I set an appointment date 2 days ahead
(02:31:40 PM) po_taka-work: and handle it in featureContext ?
(02:32:21 PM) everzet: yes, add new step definition, and you can even use another, more technical steps from it (or even Mink api directly)
(02:33:02 PM) po_taka-work: but then when i test is it really saved with that date
(02:33:04 PM) everzet: this is the whole idea of Gherkin/Behat/cucumber – research/define your domain area by describing application features
(02:33:19 PM) po_taka-work: i should write new step for “Then i should see tomorrow”
(02:33:25 PM) everzet: yes
(02:33:53 PM) everzet: you should write tests for your domain, because no one can do it for you, because no one can know your domain better than you
(02:34:47 PM) po_taka-work: ok i will think about it,
(02:34:47 PM) po_taka-work: But why there is a option to change steps ?
(02:35:01 PM) everzet: to change steps?
(02:35:57 PM) everzet: you mean nodes API ?
(02:36:01 PM) po_taka-work: (02:25:57 PM) everzet: DON’T change steps in runtime
(02:36:16 PM) everzet: it’s NodeTree
(02:36:23 PM) everzet: it’s used by parser to fill nodes
(02:38:11 PM) everzet: or can be used to create node-tree by hand to dump it later into feature
(02:38:40 PM) everzet: but it’s not here to modify features runtime
(02:38:47 PM) everzet: *in_runtime
(02:38:58 PM) po_taka-work: ok got it
(02:40:16 PM) po_taka-work: is it good to create new step definitions like ones from minkContext,
(02:40:25 PM) po_taka-work:  but i will use ‘ for parameters instead of ”
(02:40:37 PM) po_taka-work: and i will have logic
(02:40:50 PM) everzet: wha?
(02:41:07 PM) po_taka-work: wait, i will write example
(02:41:08 PM) po_taka-work: 2 min
(02:41:26 PM) everzet: ?
(02:49:19 PM) po_taka-work:
(02:50:54 PM) po_taka-work: this way i can use
(02:50:54 PM) po_taka-work: I fill “element” with “some text”
(02:50:54 PM) po_taka-work: I fill “element” with ‘tomorrow’
(02:51:00 PM) po_taka-work: is this ok ?
(02:59:03 PM) po_taka-work: are there IRC logs, book, forum or something familiar, probably i’m not the first one asking these things 🙂
(03:05:16 PM) everzet: I fill “element” with ‘tomorrow’
(03:05:19 PM) everzet: looks ok to you?
(03:05:29 PM) everzet: for me it looks totally unreadable
(03:05:49 PM) everzet: users don’t think about filling forms this way
(03:05:53 PM) everzet: *usually
(03:05:54 PM) everzet: 🙂
(03:06:05 PM) everzet: it depends from what point you’re describing your feature
(03:06:15 PM) l3l0 [[email protected]] entered the room.
(03:06:34 PM) everzet: but usually it’s something like “I choose tomorrow in birthday datefield”
(03:06:40 PM) everzet: or something like that
(03:08:38 PM) everzet: got it?
(03:08:50 PM) po_taka-work: yes, but it sounds like a lot of code
(03:08:56 PM) everzet: no it’s not
(03:09:10 PM) everzet: 1. keep your definitions short
(03:09:13 PM) everzet: 2. reuse them
(03:09:17 PM) everzet: 3. define your domain
(03:09:39 PM) everzet: yes, eventually you will have a lot of definitions to define your domain area of project
(03:09:44 PM) everzet: but after that
(03:09:48 PM) everzet: you will just use it
(03:12:02 PM) po_taka-work: ( fill, view, choose, value is ) x ( tomorrow, yesterday, next week, last week) = code i should write and reuse ?
(03:13:47 PM) po_taka-work: every 1 in different steDefinition ?
(03:13:52 PM) everzet: why?
(03:14:07 PM) everzet: you can’t create one single step definition, which will use strtotime() ?
(03:14:24 PM) everzet: THIS IS code reuse
(03:14:39 PM) po_taka-work: each one for (fill, view, choose) … right ?
(03:15:57 PM) everzet: why ?
(03:16:20 PM) everzet: ok
(03:16:25 PM) everzet: let’s start from different point
(03:16:34 PM) everzet: imagine that you don’t have Mink and predefined steps
(03:16:53 PM) everzet: describe feature in YOUR OWN words, that fit domain logic, that you’re describing
(03:17:05 PM) everzet: I go to event creation page
(03:17:40 PM) everzet: I set event date to tomorrow
(03:17:51 PM) everzet: I fill event name with “New event”
(03:18:17 PM) everzet: I press “Save”
(03:18:20 PM) everzet: see?
(03:18:31 PM) everzet: highly readable
(03:18:38 PM) everzet: no technical details
(03:18:41 PM) everzet: highly reusable
(03:18:48 PM) everzet: domain-oriented
(03:18:51 PM) everzet: this is your aim
(03:19:05 PM) po_taka-work: got it
(03:19:24 PM) po_taka-work: i tried to move logic to gherkin, witch is bad
(03:19:34 PM) everzet: YES
(03:19:35 PM) everzet: 🙂
(03:19:39 PM) everzet: you got it
(03:20:03 PM) everzet: and don’t worry, there wouldn’t be much step definitions at the end
(03:20:13 PM) everzet: you will just define your domain dictionary and that’s it
(03:21:06 PM) everzet: but in the process, you’ll get amazing feature descriptions, that you will be able to gloriously show to anyone, even to your mom 😉
(03:21:43 PM) everzet: and as a consequense, you will understand every important aspect of your domain (project)
(03:21:43 PM) po_taka-work: tnx, u spend 1 hour to this, awesome 🙂
(03:22:58 PM) everzet: np, love to help
(03:24:43 PM) elblinkin [[email protected]] entered the room.
(03:52:21 PM) po_taka-work: its ok to have complex technical step and call it from other ‘simple’ steps. But never use it in gherkin, right ?
(03:52:21 PM) po_taka-work: gherkin: Then set event date for tomorrow
(03:52:21 PM) po_taka-work: in step definition i can call “Then i fill <element> with <{tomorrow}>”
(03:54:18 PM) Stof: po_taka-work: you don’t even need to make it a step if you never use it as a step. It could be a protected method of the FeatureContext called by the steps
(03:55:06 PM) po_taka-work: yes, i should just call the method
(03:55:08 PM) po_taka-work: tnx Stof
(04:00:11 PM) everzet: po_taka-work: but there’s nothing wrong in, for example, calling internal Mink steps from your domain definitions. It could even help reusability
(04:02:09 PM) po_taka-work: yea, i hope i got it, tnx again

This entry was posted in BDD, Programming, Testing. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *