Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to represent nested json objects in a cucumber feature file

I have a need to represent JSON object in the feature file. I could use a json file for this for the code to pick up. But this would mean that i cant pass values from the feature file.

Scenario: Test

Given a condition is met

Then the following json response is sent
 | json |
 | {"dddd":"dddd","ggggg":"ggggg"}|

Above works for a normal json. However if there are nested objects etc then writing the json in a single line like above would make the feature very difficult to read and difficult to fix.

Please let me know.

like image 445
trial999 Avatar asked Nov 27 '15 17:11

trial999


1 Answers

You can use a string to do that, it makes the json much more legible.

Then the following json response is sent
  """
   {
      'dddd': 'dddd',
      'ggggg': 'ggggg',
      'somethingelse': {
        'thing': 'thingvalue',
        'thing2': 'thing2value'
      }
    }
  """

In the code, you can use it directly:

Then(/^the following json response is sent$/) do |message|
  expect(rest_stub.body).to eq(message)
end

or something like that.

like image 119
Dave McNulla Avatar answered Oct 05 '22 14:10

Dave McNulla