# \[Cucumber\] How can I pass an XML block as a parameter?

**URL:** <https://www.ruby-forum.com/t/cucumber-how-can-i-pass-an-xml-block-as-a-parameter/165541>\
**Category:** RSpec\
**Created:** [April 15, 2009, 1:39am UTC](https://www.ruby-forum.com/t/cucumber-how-can-i-pass-an-xml-block-as-a-parameter/165541 "2009-04-15T01:39:26Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![wolframarnold](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/a88e57/32.png) [@wolframarnold](https://www.ruby-forum.com/u/wolframarnold)\
**Post date:** [April 15, 2009, 1:39am UTC](https://www.ruby-forum.com/t/cucumber-how-can-i-pass-an-xml-block-as-a-parameter/165541/1 "2009-04-15T01:39:26Z")

</div>

We’re trying to verify XML REST API’s and would like to write Cucumber  
specs of the following type:

Scenario: Create a phrase  
Given I have an authenticated session for user with login “steve”  
When I send a POST to /phrases with parameters: locale=ca and post  
body  
“\<?xml version="1.0" encoding="UTF-8"?\>  
  
060e985b-0307-4c8f-b43f-c16f0e45196d  
Fake Catalan Source  
\<source\_language\>ca\</source\_language\>  
”  
Then I get a 201 (created) status result  
And I a phrase object with UUID=060e985b-0307-4c8f-b43f-c16f0e45196d  
exists on the server

In other words, we’re trying to pass a multi-line value to the parser.  
We’ve found this reference:  
[https://rspec.lighthouseapp.com/projects/16211/tickets/4-add-multiline-step-support](https://rspec.lighthouseapp.com/projects/16211/tickets/4-add-multiline-step-support)  
It’s marked as resolved, but we can’t seem to get it to work with the  
“…” syntax.

The parser statement is:

When /^I send a (GET|POST|PUT|DELETE) to ([/\w]+)(?: with parameters:  
)?(._) and post body (._)$/m do |method, path, params, body|  
send(method.downcase.to\_sym, path, params)  
end

The error:

$ cucumber features/phrases\_xml.feature -n  
/usr/lib/ruby/gems/1.8/gems/cucumber-0.2.3/bin/…/lib/cucumber/parser/treetop\_ext.rb:42:in  
`parse_or_fail': features/phrases_xml.feature:9:6: Parse error, expected one of "|", "\n", "\r", "\"\"\"", "#", "Given", "When", "Then", "And", "But", "@", "Scenario", "Scenario Outline". (Cucumber::Parser::SyntaxError) from /usr/lib/ruby/gems/1.8/gems/cucumber-0.2.3/bin/../lib/cucumber/parser/treetop_ext.rb:28:in `parse\_file’  
from  
/usr/lib/ruby/gems/1.8/gems/cucumber-0.2.3/bin/…/lib/cucumber/parser/treetop\_ext.rb:33:in  
`open' from /usr/lib/ruby/gems/1.8/gems/cucumber-0.2.3/bin/../lib/cucumber/parser/treetop_ext.rb:33:in `parse\_file’  
from  
/usr/lib/ruby/gems/1.8/gems/cucumber-0.2.3/bin/…/lib/cucumber/cli/main.rb:55:in  
`load_plain_text_features' from /usr/lib/ruby/gems/1.8/gems/cucumber-0.2.3/bin/../lib/cucumber/cli/main.rb:54:in `each’  
from  
/usr/lib/ruby/gems/1.8/gems/cucumber-0.2.3/bin/…/lib/cucumber/cli/main.rb:54:in  
`load_plain_text_features' from /usr/lib/ruby/gems/1.8/gems/cucumber-0.2.3/bin/../lib/cucumber/cli/main.rb:37:in `execute!’  
from  
/usr/lib/ruby/gems/1.8/gems/cucumber-0.2.3/bin/…/lib/cucumber/cli/main.rb:20:in  
`execute' from /usr/lib/ruby/gems/1.8/gems/cucumber-0.2.3/bin/cucumber:6 from /usr/bin/cucumber:19:in `load’  
from /usr/bin/cucumber:19

---

<div class="post-metadata">

**Author:** ![wolframarnold](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/a88e57/32.png) [@wolframarnold](https://www.ruby-forum.com/u/wolframarnold)\
**Post date:** [April 15, 2009, 1:40am UTC](https://www.ruby-forum.com/t/cucumber-how-can-i-pass-an-xml-block-as-a-parameter/165541/2 "2009-04-15T01:40:46Z")

</div>

Copy & paste mistake: We did escape the quotes inside the XML stanza,  
result is the same.

---

<div class="post-metadata">

**Author:** ![wolframarnold](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/a88e57/32.png) [@wolframarnold](https://www.ruby-forum.com/u/wolframarnold)\
**Post date:** [April 15, 2009, 2:49am UTC](https://www.ruby-forum.com/t/cucumber-how-can-i-pass-an-xml-block-as-a-parameter/165541/3 "2009-04-15T02:49:06Z")

</div>

On Apr 14, 2009, at 5:39 PM, Wolfram Arnold wrote:

> ```
> <text>Fake Catalan Source</text>
> <source_language>ca</source_language>
> </phrase>"
> 
> ```
> 
> Then I get a 201 (created) status result  
> And I a phrase object with UUID=060e985b-0307-4c8f-b43f-  
> c16f0e45196d  
> exists on the server
> 
> In other words, we’re trying to pass a multi-line value to the parser.

Have you tried the pystring syntax?

Given I want to have multiple lines  
“”"  
I can pass them  
in with three quotes…  
“”"

-Ben

---

<div class="post-metadata">

**Author:** ![wolframarnold](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/a88e57/32.png) [@wolframarnold](https://www.ruby-forum.com/u/wolframarnold)\
**Post date:** [April 15, 2009, 5:00am UTC](https://www.ruby-forum.com/t/cucumber-how-can-i-pass-an-xml-block-as-a-parameter/165541/4 "2009-04-15T05:00:11Z")

</div>

On Tue, Apr 14, 2009 at 10:37 PM, Stephen E. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> How does that parse into a step definition? Would it be:
> 
> Given /^I want to have multiple lines\n(.\*)$/m do |text|

```
Given /^I want to have multiple lines$/m do |text|

```

Cucumber parses it and appends it to the blocks argument list—so it  
will always be the last argument. e.g.

```
Given /^(\w+) want to have multiple lines$/m do |who, text|

```

It is a cucumber PyString object, but you can treat it like a normal  
string.

> simple syntax reference.  
> [http://rubyforge.org/mailman/listinfo/rspec-users](http://rubyforge.org/mailman/listinfo/rspec-users)

–  
Zach D.  
[http://www.continuousthinking.com](http://www.continuousthinking.com)

> **[Homepage | Mutually Human](https://www.mutuallyhuman.com)**
>
> We empower businesses to overcome challenges with a holistic focus on People, Process, and Technology for lasting results and innovation.

---

<div class="post-metadata">

**Author:** ![wolframarnold](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/a88e57/32.png) [@wolframarnold](https://www.ruby-forum.com/u/wolframarnold)\
**Post date:** [April 15, 2009, 4:46am UTC](https://www.ruby-forum.com/t/cucumber-how-can-i-pass-an-xml-block-as-a-parameter/165541/5 "2009-04-15T04:46:10Z")

</div>

On Tue, Apr 14, 2009 at 8:37 PM, Ben M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Have you tried the pystring syntax?
> 
> Given I want to have multiple lines  
> “”"  
> I can pass them  
> in with three quotes…  
> “”"

How does that parse into a step definition? Would it be:

Given /^I want to have multiple lines\n(.\*)$/m do |text|

…or would it be something else? Is the newline character necessary?  
Are the quotes included? And does this imply that multiline text  
must always be separated from from steps in lines of its own?

Sorry if I’m asking dumb questions, but I was trying to look this up a  
few weeks ago myself to represent some example Markdown data, and  
eventually gave up. This isn’t documented anywhere that I could find.  
I’ve also never heard of pystring syntax – I just tried to Google  
that too, but all I got were references to Java libraries and no  
simple syntax reference.

–  
Have Fun,  
Steve E. ([removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid))  
ESCAPE POD - The Science Fiction Podcast Magazine  
[http://www.escapepod.org](http://www.escapepod.org)

---

<div class="post-metadata">

**Author:** ![wolframarnold](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/a88e57/32.png) [@wolframarnold](https://www.ruby-forum.com/u/wolframarnold)\
**Post date:** [April 15, 2009, 5:19am UTC](https://www.ruby-forum.com/t/cucumber-how-can-i-pass-an-xml-block-as-a-parameter/165541/6 "2009-04-15T05:19:30Z")

</div>

On Tue, Apr 14, 2009 at 10:37 PM, Stephen E. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Sorry if I’m asking dumb questions, but I was trying to look this up a  
> few weeks ago myself to represent some example Markdown data, and  
> eventually gave up. This isn’t documented anywhere that I could find.  
> I’ve also never heard of pystring syntax – I just tried to Google  
> that too, but all I got were references to Java libraries and no  
> simple syntax reference.

All right, never mind. Having been given enough clues that the  
feature exists and what it generally might look like, I prowled  
through Cucumber’s specs and examples until I got a clearer picture.  
Then, to keep my ‘There ain’t no documentation!’ whining privileges, I  
went and added what I learned to the wiki:

[http://wiki.github.com/aslakhellesoy/cucumber/multiline-step-arguments](http://wiki.github.com/aslakhellesoy/cucumber/multiline-step-arguments)

I’d call it my minor good deed for the day, but really I was using it  
to procrastinate on my podcasting work for another half hour, so  
overall it was morally neutral.

–  
Have Fun,  
Steve E. ([removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid))  
ESCAPE POD - The Science Fiction Podcast Magazine  
[http://www.escapepod.org](http://www.escapepod.org)

---

<div class="post-metadata">

**Author:** ![wolframarnold](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/a88e57/32.png) [@wolframarnold](https://www.ruby-forum.com/u/wolframarnold)\
**Post date:** [April 15, 2009, 7:15am UTC](https://www.ruby-forum.com/t/cucumber-how-can-i-pass-an-xml-block-as-a-parameter/165541/7 "2009-04-15T07:15:57Z")

</div>

> > simple syntax reference.  
> > to procrastinate on my podcasting work for another half hour, so  
> > overall it was morally neutral.

Allright allright. You _will_ be allowed into Cucumber heaven 🙂

Aslak

---

<div class="post-metadata">

**Author:** ![wolframarnold](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/a88e57/32.png) [@wolframarnold](https://www.ruby-forum.com/u/wolframarnold)\
**Post date:** [April 15, 2009, 6:45am UTC](https://www.ruby-forum.com/t/cucumber-how-can-i-pass-an-xml-block-as-a-parameter/165541/8 "2009-04-15T06:45:29Z")

</div>

Stephen E. wrote:

> All right, never mind. Having been given enough clues that the

lol.. Sorry for not explaining the syntax better… What you wrote on  
the wiki is great and doesn’t really need further explanation by Ben  
Mabey or anyone else IMO. 😉

I’ll go ahead and elaborate on it though. Thanks for adding the page.

-Ben

---

<div class="post-metadata">

**Author:** ![wolframarnold](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/a88e57/32.png) [@wolframarnold](https://www.ruby-forum.com/u/wolframarnold)\
**Post date:** [April 15, 2009, 9:18am UTC](https://www.ruby-forum.com/t/cucumber-how-can-i-pass-an-xml-block-as-a-parameter/165541/9 "2009-04-15T09:18:29Z")

</div>

On Wed, Apr 15, 2009 at 6:34 AM, Ben M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > simple syntax reference.
> 
> I’ll go ahead and elaborate on it though. Thanks for adding the page.

Not sure if you have already, but I have done some serious wiki  
refactoring  
around this this morning:

- Moved some stuff from the “Using tabular data in features” into the  
new  
“multiline-step-arguments” page
- Deleted the “Using tabular data in features” page (it was now  
obsolete)

I also cleared up a little misunderstanding around PyString (you’ll  
never  
see that in your step definitions - just String).

Aslak

---

<div class="post-metadata">

**Author:** ![wolframarnold](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/a88e57/32.png) [@wolframarnold](https://www.ruby-forum.com/u/wolframarnold)\
**Post date:** [April 15, 2009, 7:41am UTC](https://www.ruby-forum.com/t/cucumber-how-can-i-pass-an-xml-block-as-a-parameter/165541/10 "2009-04-15T07:41:42Z")

</div>

On Wed, Apr 15, 2009 at 1:12 AM, Aslak  
Hellesøy[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Allright allright. You _will_ be allowed into Cucumber heaven 🙂

Woohoo! That makes me so happy that I won’t share any of the dirty  
jokes that sentence evokes. \>8-\>

–  
Have Fun,  
Steve E. ([removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid))  
ESCAPE POD - The Science Fiction Podcast Magazine  
[http://www.escapepod.org](http://www.escapepod.org)

---

<div class="post-metadata">

**Author:** ![wolframarnold](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/a88e57/32.png) [@wolframarnold](https://www.ruby-forum.com/u/wolframarnold)\
**Post date:** [April 15, 2009, 8:24pm UTC](https://www.ruby-forum.com/t/cucumber-how-can-i-pass-an-xml-block-as-a-parameter/165541/11 "2009-04-15T20:24:05Z")

</div>

Thanks to all for the prompt answer and new docs!!!
