2009-01-29 12:37:10 +08:00
|
|
|
Feature: Handles Multiple Formats
|
|
|
|
|
|
|
|
As a developer
|
|
|
|
I want to be able to consume remote services of many different formats
|
|
|
|
And I want those formats to be automatically detected and handled
|
|
|
|
Because web services take many forms
|
|
|
|
And I don't want to have to do any extra work
|
|
|
|
|
|
|
|
Scenario: An HTML service
|
|
|
|
Given a remote service that returns '<h1>Some HTML</h1>'
|
2010-07-07 08:54:22 -04:00
|
|
|
And that service is accessed at the path '/html_service.html'
|
2009-01-29 12:37:10 +08:00
|
|
|
And the response from the service has a Content-Type of 'text/html'
|
2010-07-07 08:54:22 -04:00
|
|
|
When I call HTTParty#get with '/html_service.html'
|
2009-01-29 12:37:10 +08:00
|
|
|
Then it should return a String
|
|
|
|
And the return value should match '<h1>Some HTML</h1>'
|
|
|
|
|
2014-02-08 18:32:43 +01:00
|
|
|
Scenario: A CSV service
|
2014-02-08 18:55:04 +01:00
|
|
|
Given a remote service that returns:
|
2014-02-08 19:07:11 +01:00
|
|
|
"""
|
2014-02-08 18:55:04 +01:00
|
|
|
"Last Name","Name"
|
2014-02-08 18:32:43 +01:00
|
|
|
"jennings","waylon"
|
2014-02-08 18:55:04 +01:00
|
|
|
"cash","johnny"
|
2014-02-08 19:07:11 +01:00
|
|
|
"""
|
2014-02-08 18:32:43 +01:00
|
|
|
And that service is accessed at the path '/service.csv'
|
|
|
|
And the response from the service has a Content-Type of 'application/csv'
|
|
|
|
When I call HTTParty#get with '/service.csv'
|
2014-02-08 19:07:11 +01:00
|
|
|
Then it should return a multidimensional array equaling: '[["Last Name","Name"],["jennings","waylon"],["cash","johnny"]]'
|
2014-02-08 18:32:43 +01:00
|
|
|
|
2009-01-29 12:37:10 +08:00
|
|
|
Scenario: A JSON service
|
|
|
|
Given a remote service that returns '{ "jennings": "waylon", "cash": "johnny" }'
|
|
|
|
And that service is accessed at the path '/service.json'
|
|
|
|
And the response from the service has a Content-Type of 'application/json'
|
|
|
|
When I call HTTParty#get with '/service.json'
|
|
|
|
Then it should return a Hash equaling:
|
|
|
|
| key | value |
|
|
|
|
| jennings | waylon |
|
|
|
|
| cash | johnny |
|
|
|
|
|
|
|
|
Scenario: An XML Service
|
|
|
|
Given a remote service that returns '<singer>waylon jennings</singer>'
|
|
|
|
And that service is accessed at the path '/service.xml'
|
|
|
|
And the response from the service has a Content-Type of 'text/xml'
|
|
|
|
When I call HTTParty#get with '/service.xml'
|
|
|
|
Then it should return a Hash equaling:
|
|
|
|
| key | value |
|
|
|
|
| singer | waylon jennings |
|
2013-09-27 11:56:27 -04:00
|
|
|
|
|
|
|
Scenario: A Javascript remote file
|
|
|
|
Given a remote service that returns '$(function() { alert("hi"); });'
|
|
|
|
And that service is accessed at the path '/service.js'
|
|
|
|
And the response from the service has a Content-Type of 'application/javascript'
|
|
|
|
When I call HTTParty#get with '/service.js'
|
|
|
|
Then it should return a String
|
|
|
|
And the return value should match '$(function() { alert("hi"); });'
|