Sha256: ce944322564ee1bfcffa35cae9927a2b3ad606b7798dcc7ea50947c7d0e01c64

Contents?: true

Size: 1.23 KB

Versions: 3

Compression:

Stored size: 1.23 KB

Contents

require 'helper'

require 'tempfile'
class Tempfile
  class TriedToUseMe < RuntimeError; end
  def initialize(*args)
    raise TriedToUseMe
  end
end

class TestEat < Test::Unit::TestCase
  def setup
    ::Eat.config.remote_timeout = 10
  end
  
  def test_filesystem
    assert eat(__FILE__).include?('class TestEat < Test::Unit::TestCase')
  end
  
  def test_http
    assert eat('http://brighterplanet.com/robots.txt').include?('User-agent')
  end
  
  def test_https
    assert eat('https://brighterplanet.com/robots.txt').include?('User-agent')
  end
  
  def test_sudo_filesystem
    f = File.open('test_sudo_filesystem.txt', 'w')
    f.write "hello world"
    f.close
    `sudo chown root #{f.path}`
    `sudo chmod go-rwx #{f.path}`
    assert !File.readable?(f.path)
    assert eat(f.path).include?('hello world')
  ensure
    `sudo rm -f #{f.path}`
  end
  
  def test_openuri_uses_tempfile
    assert_raises(Tempfile::TriedToUseMe) do
      require 'open-uri'
      open 'http://do1ircpq72156.cloudfront.net/0.2.47/javascripts/prototype.rails-3.0.3.js'
    end
  end
  
  def test_eat_doesnt_use_tempfile
    assert_nothing_raised do
      eat 'http://do1ircpq72156.cloudfront.net/0.2.47/javascripts/prototype.rails-3.0.3.js'
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
eat-0.0.5 test/test_eat.rb
eat-0.0.4 test/test_eat.rb
eat-0.0.3 test/test_eat.rb