Generating binary files with Sitespec fails when a Padrino Rack app

80 views Asked by At

I am working on a project with Sitespec, which is a static site generator using RSpec and uses any Rack app. I chose Padrino as a Rack app for Sitespec.

Then, I get the following errors when I do rspec at some URLs of Content-type: image/png type.

Failures:

  1) Sitespec GET public/images/simple-image1.png Generate a static image public/images/simple-image1.png
     Failure/Error: pathname.write(response.body)

     Encoding::UndefinedConversionError:
       "\x89" from ASCII-8BIT to UTF-8

Pathname.write(response.body) is going to try to convert it to UTF-8.

But when I use Sinatra instead of Padrino, the error does not occur.

I made simple sample projects for comparison:

Question: Why does the Padrino project fail and how do I fix the errors?

By the way, doing monkey patch

module Sitespec
  class Artifact
    def generate_file
      pathname.binwrite(response.body)
    end
  end
end

eliminates the error. (Replacing Pathname#write to Pathname#binwrite.)

0

There are 0 answers