spec/spec_helper.rb in clamby-1.4.0 vs spec/spec_helper.rb in clamby-1.5.0

- old
+ new

@@ -1,8 +1,30 @@ require 'bundler/setup' Bundler.setup +require 'open-uri' +require 'tempfile' + require 'clamby' # and any other gems you need RSpec.configure do |config| - # some (optional) config here -end \ No newline at end of file + config.mock_with :rspec do |mocks| + # so that Command can keep doing what it always does. + mocks.verify_partial_doubles = true + end + + def download(url) + file = open(url) + file.is_a?(StringIO) ? to_tempfile(file) : file + end + + # OpenURI returns either Tempfile or StringIO depending of the size of + # the response. We want to unify this and always return Tempfile. + def to_tempfile(io) + tempfile = Tempfile.new('tmp') + tempfile.binmode + ::OpenURI::Meta.init(tempfile, io) + tempfile << io.string + tempfile.rewind + tempfile + end +end