These are chat archives for Behat/Behat

27th
Oct 2014
Alex Panshin
@enl
Oct 27 2014 08:49
Hi there. I have a question about reusing small steps. Here in my project I have some Context classes
These classes provide different steps grouped by functionality: for example, FormContext provides some widget fillers ad checkers and so on. How can I combine some small steps into big one. For example, step "I am logged as :name" can be written as a stack of steps like "I go to login page", "I fill the form with:" and so on. The problem is that I cannot simply call the methods: they are in different Context.
Is there any way to make such a combination? Or maybe it was wrong idea to split steps into different contexts? How to manage tons of steps in one class if so?
Ignacio Tolstoy
@naxhh
Oct 27 2014 08:55
@enl I may be wrong here. But for me contexts are your Website, or your Core domain code. So you have a Context that performs the login from the website using forms and you have another context that performs the login using your code. Something like: http://everzet.com/post/99045129766/introducing-modelling-by-example
This way you re-use your step to test code logic and also final implementation
Alex Panshin
@enl
Oct 27 2014 08:58
@naxhh thanks for link, gonna read this now:)
Alex Panshin
@enl
Oct 27 2014 09:40
@naxhh Ok, I've read the article. Let's return to my question:) Step "I am logged as :name" uses both Website code (form form filling) and CoreDomain code (create user to login) contexts. How can I combine them into one step and not to repeat myself?
Ignacio Tolstoy
@naxhh
Oct 27 2014 09:41
Why you want to combine two contexts steps into one? Can you post a gist example of the code? And why you want to define a step only once if they have different implementation?
I think I'm not getting the point here.
Alex Panshin
@enl
Oct 27 2014 09:46
Ok, stupid example of test. As a logged user I need to see info about me in the /account page
Given I am logged as ":name"
When I go to my account page
Then I should see my firstname and email
The step "I am logged as name" consists of two things, actually: "there is user :name" and some form filling.
Ignacio Tolstoy
@naxhh
Oct 27 2014 10:56
ok
I think I see the problem now
So you have two steps like "there is user :name" and "the form is filled with :something adn :something" for example and you want to re-use that in the step I am logged as name
is that?
Alex Panshin
@enl
Oct 27 2014 10:57
exactly!:)
Ignacio Tolstoy
@naxhh
Oct 27 2014 10:58
And you want to re-use that in both contexts or only in the "web" context?
Alex Panshin
@enl
Oct 27 2014 10:58
only in web.
but step "there is use :name" exists in domain context.
Ignacio Tolstoy
@naxhh
Oct 27 2014 11:01
oh. I see. you want to use a defined step form the core in the web
two things here
calling steps from steps. Was not as good as core devs think in behat v2
see: Behat/Behat#546 for more info
In the other hand. I think the better approach is to have an Object that actually perform the operation you defined in the Core context
And re-define the step in both contexts calling to that object to perform the operation
As I said is what "I" think is better approach. Maybe there is another way
Alex Panshin
@enl
Oct 27 2014 11:06
@naxhh Thanks for your help. I have now something to think of:)
Ignacio Tolstoy
@naxhh
Oct 27 2014 11:07
glad to help