[rspec-users] [Cucumber] How can I pass an XML block as a parameter?

Wolfram Arnold lists at ruby-forum.com
Tue Apr 14 19:39:26 EDT 2009


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"?>
        <phrase>
            <uuid>060e985b-0307-4c8f-b43f-c16f0e45196d</uuid>
            <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.
We've found this reference:
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
-- 
Posted via http://www.ruby-forum.com/.


More information about the rspec-users mailing list