hidroh / cucumber-api

API validator in BBD style with Cucumber
https://rubygems.org/gems/cucumber-api
Apache License 2.0
52 stars 56 forks source link

How to do a PUT/POST with content type as text/plain? #18

Open sandeepnagra opened 7 years ago

sandeepnagra commented 7 years ago

I tried something like:

Scenario: Try to set keep data value under database settings with response code 200 Given I send "text/plain" and accept JSON When I send a PUT request to "http://hostname:8080/settings/databaseSettings/dataRetention" with: | 90 | Then the response status should be "200"

But it fails. I have always used JSON request body, this is the first REST API which needs plain text and I am trying to figure out how to do it.

sandeepnagra commented 7 years ago

Temporarily, I have created following custom step:

When(/^I set request body to "(.*?)"$/) do |value| @body = value end

and then the following scenario works:

Scenario: Try to set keep data value under database settings with response code 200 Given I send "text/plain" and accept JSON And I set request body to "90" When I send a PUT request to "http://hostname:8080/settings/databaseSettings/dataRetention" Then the response status should be "200"

hidroh commented 7 years ago

That would be my approach for this as well. Make a PR, probably adding a sample and I'll merge it!