Sha256: c55b4cc6a03e72a21234f6203859fe885cab9fa0a84b193c1cb5ba7485457a44
Contents?: true
Size: 1.84 KB
Versions: 2
Compression:
Stored size: 1.84 KB
Contents
require "helper" # these actually use the network, and get skipped unless ENV["NETWORK"]. class TestNetwork < Minitest::Test include Helper def after_setup skip if !ENV["NETWORK"] end def test_get response = client.get("http://httpbin.org/get") assert_equal 200, response.code end def test_timeout e = assert_raises Chuckle::Error do client(nretries: 0, timeout: 2).get("http://httpbin.org/delay/3") end assert e.timeout?, "exception didn't indicate timeout" end def test_post response = client.post("http://httpbin.org/post", QUERY) assert_equal JSON.parse(response.body)["form"], QUERY end def test_cookies cookies = { "a" => "b" } client(cookies: true, expires_in: 60) # set options request = client.create_request("http://httpbin.org/get") cookie_jar = Chuckle::CookieJar.new(request).path # make sure there are no cookies after the GET client.run(request) assert !File.exists?(cookie_jar), "cookie jar shouldn't exist yet" # make sure there ARE cookies after a Set-Cookie client.get("http://httpbin.org/cookies/set?#{Chuckle::Util.hash_to_query(cookies)}") assert File.exists?(cookie_jar), "cookie jar SHOULD exist now" # make sure cookies come back from the server response = client.get("http://httpbin.org/cookies") assert_equal JSON.parse(response.body)["cookies"], cookies # Finally, test cache expiry on cookie_jar. Note that this has to # be an un-cached URL, otherwise the cookie_jar never gets # checked! tm = Time.now - (client.expires_in + 9999) File.utime(tm, tm, cookie_jar) client.get("http://httpbin.org/robots.txt") assert !File.exists?(cookie_jar), "cookie jar should've expired" end def test_bin Dir.chdir(File.expand_path("../", __FILE__)) assert_command("../bin/chuckle url_file.txt") end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
chuckle-1.0.3 | test/test_network.rb |
chuckle-1.0.2 | test/test_network.rb |