Faking I/O with StringIO

Long before Ruby on Rails came along, the first web applications were simple command-line scripts that wrote their content to the console. This Common Gateway Interface (CGI) architecture made it possible to build dynamic websites in nearly any language.[114] All you had to do was read your input from environment variables and write the resulting web page to stdout.

Here’s a CGI script that functions as a simple little Ruby documentation server. If you were to hook this code up to a local web server and visit http://localhost/String/each, it would return a JSON array of all the String methods that begin with each: ["each_byte", "each_char", ...].

Get Effective Testing with RSpec 3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.