Sunday, August 14, 2011

Testing Git-scribe

‹prev | My Chain | next›

I am fairly content with my mobi-from-epub branch of git-scribe.

In addition to producing (what I consider) far superior output, I can also generate a ZIP file containing the PDF, EPUB, and MOBI versions of an ebook with git-scribe gen ebook. For The SPDY Book, this command produces with the following contents:
➜  output git:(master) unzip -l
Length      Date    Time    Name
---------  ---------- -----   ----
0  2011-08-14 21:22   the_spdy_book/
5157721  2011-08-14 21:22   the_spdy_book/the_spdy_book.pdf
8162511  2011-08-14 21:22   the_spdy_book/
5199521  2011-08-14 21:22   the_spdy_book/the_spdy_book.epub
---------                     -------
18519753                     4 files
I had been doing that manually before uploading it to the SPDY Book site.

The only thing left at this point is to get all of the tests passing (and maybe write one or two of my own). There are three test files and one helper in the most recent git-scribe:
➜  git-scribe git:(mobi-from-epub) ls test
check_test.rb  gen_test.rb  init_test.rb  test_helper.rb
Of the three test files, only gen_test.rb has any failures. Unfortunately, all but one of those tests is still passing:
➜  git-scribe git:(mobi-from-epub) ruby test/gen_test.rb
Loaded suite test/gen_test
Finished in 3.532684 seconds
Working backwards, the last failure is caused when trying to generate a web site version of the book:
6) Error:
Errno::ENOENT: No such file or directory - index.html
/home/cstrom/repos/git-scribe/lib/git-scribe/generate.rb:330:in `read'
/home/cstrom/repos/git-scribe/lib/git-scribe/generate.rb:330:in `clean_site'
/home/cstrom/repos/git-scribe/lib/git-scribe/generate.rb:121:in `block in do_site'
/home/cstrom/repos/git-scribe/lib/git-scribe/generate.rb:116:in `chdir'
/home/cstrom/repos/git-scribe/lib/git-scribe/generate.rb:116:in `do_site'
/home/cstrom/repos/git-scribe/lib/git-scribe/generate.rb:21:in `block (2 levels) in gen'
/home/cstrom/repos/git-scribe/lib/git-scribe/generate.rb:18:in `each'
/home/cstrom/repos/git-scribe/lib/git-scribe/generate.rb:18:in `block in gen'
/home/cstrom/repos/git-scribe/lib/git-scribe/generate.rb:17:in `chdir'
/home/cstrom/repos/git-scribe/lib/git-scribe/generate.rb:17:in `gen'
The first thing that I need to change here is not an error, but to make the gen method testable. I had been using a constant to store the current working directory at compile time:
class GitScribe
module Generate
WD = Dir.getwd
To make this testable, I need to switch that to a runtime instance variable:
class GitScribe
module Generate
def gen(args = [])
# ...
@wd = Dir.getwd
The test is still failing at this point because I have moved the target directory from output (where it was getting conflated with output from other generators) into output/site. Changing the message (and hopefully making it pass) is easy enough—I just need to add the site sub-directory to the test:
test "scribe can generate site html" do
in_temp_dir do
Dir.chdir('t') do
data = @scribe.gen('site')
out = Dir.glob('output/**/*')
assert out.include? 'output/site/index.html'
assert out.include? 'output/site/the_first_chapter.html'
assert out.include? 'output/site/the_second_chapter.html'
assert out.include? 'output/site/image'
assert out.include? 'output/site/stylesheets/scribe.css'
The test still fails because the I renamed the image sub-directory to the plural images (on the assumption that I may want multiple images some day). The fix is easy enough:
assert out.include? 'output/site/images'
With that, I have two assertions passing from the test suite. That is a fine stopping point for tonight. I will pick back up tomorrow—hopefully finishing off the remaining tests. And maybe writing a few of my own.

Day #112

No comments:

Post a Comment