Passing multiline strings from outlines

1,525 views
Skip to first unread message

asartalo

unread,
Apr 15, 2011, 11:08:02 PM4/15/11
to Behat
Hi Everyone,

I've started using Behat only yesterday and I must say that it is very
addicting! So thanks to the Behat team for building this amazing tool.

Anyway, I've written a bunch of scenarios that take multiline strings.
But they were all doing the same thing so to be DRY, I wanted to use
outlines. Is this possible? Or if not, is there a recommended way to
do this?

Some example code. This is a demonstration of what I have:


Scenario A reverse lines scenario
Given I have some multiline string here
"""
A text that spans
two lines
"""
When I pass this to reverse
Then I should get this multiline string
"""
two lines
A text that spans
"""

Scenario Another reverse lines scenario
Given I have some multiline string here
"""
Another text that spans
three
lines
"""
When I pass this to reverse
Then I should get this multiline string
"""
lines
three
Another text that spans
"""

And I want to convert it to something like this:

Scenario Outline: Reversing lines
Given I have some <multiline string>
When I pass this to reverse
Then I should get a <reversed multiline string>

Examples:
| multiline string | reversed multiline string |
...?

Konstantin Kudryashov

unread,
Apr 17, 2011, 10:54:10 AM4/17/11
to be...@googlegroups.com
You cannot use multistring arguments in any place other than after steps. That's why they are called multistring arguments - because they are just arguments to steps.

Remember, that Behat was not developed to replace you unit or specification testing framework. Behat, Cucumber, Gherkin and Scenario BDD are all about describing testable business value expectations about future product, not about testing your product INTERNALS.

You should always balance between business value research and implementation details. Your features should firstly tell a story about future product behavior, not about it's inner implementation.

Pretend, that *.feature files is a simple talk from your product owner. I'm sure, you never hear:

    Then I should see line1 newline line2 newline line3 newline line4

Instead you always hear something like:

    Then I should see line1
    And I should see line2
    And I should see line3
    But I should not see line5

Don't describe your non-existing (yet) product implementation details with features - use them to describe future product behaviors with everyday business language, like your customers do!

--------------------------------------------------
Konstantin Kudryashov (everzet)

Konstantin Kudryashov

unread,
Apr 17, 2011, 11:03:56 AM4/17/11
to be...@googlegroups.com
Also, cover only valuable expectations of your features. By covering every part of every message on your pages you could make your product unmaintainable. Describe only expectations, that does makes value for your feature.

For example, if you have a registration page and you would like to check, that user can register, you shouldn't write:

    ...
    When I press "register"
    Then I should see:
      """
      Welcome, everzet!
      You were successfully registered on our site.
      """

Because in that case, you will need to change this scenario every time registration message change. What you actually need is to test that epxected user were registered:

    ...
    When I press "register"
    Then I should see "everzet"
    And I should see "successfully registered"

--------------------------------------------------
Konstantin Kudryashov (everzet)

asartalo

unread,
Apr 17, 2011, 11:10:32 AM4/17/11
to Behat
Hi Konstantin,

Thanks for reminding me that. I was getting ahead of myself. I did
thought about that, that this is more for making features easier to
communicate and share/validate/verify with stakeholders. But, yes, I
was trying to push it. Gherkin and Behat have a place in my toolset
and I promise too keep your wisdom in mind when I use it again. Thanks
for the great work!

On Apr 17, 10:54 pm, Konstantin Kudryashov <ever....@gmail.com> wrote:
> You cannot use multistring arguments in any place other than after steps. That's why they are called multistring arguments - because they are just arguments to steps.
>
> Remember, that Behat was not developed to replace you unit or specification testing framework. Behat, Cucumber, Gherkin and Scenario BDD are all about describing testable business value expectations about future product, not about testing your product INTERNALS.
>
> You should always balance between business value research and implementation details. Your features should firstly tell a story about future product behavior, not about it's inner implementation.
>
> Pretend, that *.feature files is a simple talk from your product owner. I'm sure, you never hear:
>
> Then I should see line1 newline line2 newline line3 newline line4
>
> Instead you always hear something like:
>
> Then I should see line1
> And I should see line2
> And I should see line3
> But I should not see line5
>
> Don't describe your non-existing (yet) product implementation details with features - use them to describe future product behaviors with everyday business language, like your customers do!
>
> --------------------------------------------------Konstantin Kudryashov (everzet)http://about.me/everzet/bio

Rodrigo Arce

unread,
Apr 17, 2011, 3:48:25 PM4/17/11
to be...@googlegroups.com
Hey asartalo

maybe you can try to put the multine in one line with \n.
E.g.

| multiline string | reversed multiline string |

| line 1\nline 2 | line 2\nline 1 |

Of course you should process the \n by yourself

Rodrigo Arce <http://rodrigoarce.com>

Reply all
Reply to author
Forward
0 new messages