RSpecでGZipされたファイルのopenをmockするメモ

require 'open-uri'
binary = open(filepath,'rb')
read = mock('open')
read.stub(:readpartial).and_return{|length| 
  binary.readpartial(length)
}
if (defined? content_encoding).nil? or content_encoding.nil?
  read.stub(:content_encoding).and_return([])     
else                               
  read.stub(:content_encoding).and_return(content_encoding)
end