-
Notifications
You must be signed in to change notification settings - Fork 14
What Is It?
canadaduane edited this page Sep 14, 2010
·
11 revisions
Ruby DocTest allows you to put your tests right in with your Ruby code. It also allows you to put tests in a separate documentation file and have the tests run automatically.
See the Example Usage page for a peek at some code.
One of the most compelling features of Ruby DocTest over other test suites is the ability to bring Interactive Ruby (irb) sessions into your code via copy/paste and to use those sessions as your tests. Let’s go through an example of this workflow.
Let’s say we want to create a Digital Object Identifier library that will give us proper bibliographic references, and vice versa. In fact, let’s say we are creating Rich Apodaca’s DOI library, just like he has it:
<pre>
module DOI
- Convert a doi into a bibliographic reference.
def biblio_for doi
doc = Hpricot(open(“http://www.crossref.org/openurl/?id=doi:#{doi}&noredirect=true&pid=ourl_sample:sample&format=unixref”))
- Convert a bibliographic reference into a DOI.
def doi_for journal, year, volume, issue, page
doc = Hpricot(open(“http://www.crossref.org/openurl/?title=#{journal.gsub(/ /, ‘%20’)}&volume=#{volume}&issue=#{issue}&spage=#{page}&date=#{year}&pid=ourl_sample:sample&redirect=false&format=unixref”))
end