streamlined geek talk

13
Streamlined Geek Talk Web Services APIs and Always Up-to-Date Documentation with Rails and Cucumber by Sarah Allen and Wolfram Arnold

Upload: sarah-allen

Post on 03-Dec-2014

1.510 views

Category:

Technology


0 download

DESCRIPTION

Web Services APIs and Always Up-to-Date Documentation with Rails and Cucumber by Sarah Allen and Wolfram Arnold

TRANSCRIPT

Page 1: Streamlined Geek Talk

Streamlined Geek Talk Web Services APIs and

Always Up-to-Date Documentation

with Rails and Cucumber

by Sarah Allen and Wolfram Arnold

Page 2: Streamlined Geek Talk

multiple clients, multiple developers

Page 3: Streamlined Geek Talk

Use cases

• Corporate teams– communication between developers– outsourced development– documenting an open API

• Open source– documenting API– interface stability

Page 4: Streamlined Geek Talk

Always up-to-date Documentation

spec = test = doc

Page 5: Streamlined Geek Talk

Server Engineerwrites code

Server Engineerwrites code

CI Pass?Client Engineerwrites code

Client Engineerwrites code

Server Engineerwrites scenarioServer Engineerwrites scenario

Covered?

Feature DocsFeature Docs

New Client App Legacy Code

Target Workflow

Page 6: Streamlined Geek Talk

How we made it happen

• Pre-existing codebase• Generate HTTP traffic logs from client apps• Wrote cucumber features for each use case

Page 7: Streamlined Geek Talk

Tools• Cucumber BDD framework – http://cukes.info/– http://wiki.github.com/aslakhellesoy/cucumber

• Webrat (gem)• Using DB fixtures in cucumber– http://wiki.github.com/aslakhellesoy/cucumber/fixtures

• Using XML fixtures to compare server response– xmlsubsetmatcher library

• Continuous integration – hudson, cruisecontrol.rb, integrity

• Example:– http://github.com/mightyverse/cucumber_xml

Page 8: Streamlined Geek Talk

Rails Web Services

app/controllers/projects_controller.rb

respond_to do |format| format.html

# views/projects/index.html.erb format.xml

# views/projects/index.xml.builderend

Page 9: Streamlined Geek Talk

Rails Web Servicesapp/views/projects/index.xml.builder

xml.instruct!xml.projects do xml.total @projects.length @projects.each do |project| xml.project do xml.name project.name xml.notes project.notes end endend

Page 10: Streamlined Geek Talk

Feature Scenarios

Feature: Project XML API In order to read project data data As a device or client application using the XML REST interface I want to make GET requests to the /projects URL

Scenario: Get Medium When I send an XML GET to /projects.xml Then I get a 200 (success) status result And the response header Content-Type matches application/xml And the response should be a superset of the file: "xml/projects.xml"

Page 11: Streamlined Geek Talk

Workflow

• Publish doc from source repository• Continuous integration run feature scenarios

on every checkin• All engineers have access to CI• Separate test and production environments

Page 12: Streamlined Geek Talk

Results

Surfaces undocumented requirements

Highlights use of undocumented API’s

Software works well

Page 13: Streamlined Geek Talk

Always up-to-date Documentation

spec = test = doc

www.mightyverse.com

Wolfram Arnold rubyfocus.biz

Sarah Allenultrasaurus.com