Skip to content

Commit

Permalink
Move test_follow_meta into test_mechanize.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
drbrain committed Apr 11, 2011
1 parent 6049a31 commit b37bd3c
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 120 deletions.
1 change: 0 additions & 1 deletion Manifest.txt
Expand Up @@ -114,7 +114,6 @@ test/htdocs/unusual______.html
test/servlets.rb
test/ssl_server.rb
test/test_cookies.rb
test/test_follow_meta.rb
test/test_form_action.rb
test/test_form_as_hash.rb
test/test_form_button.rb
Expand Down
119 changes: 0 additions & 119 deletions test/test_follow_meta.rb

This file was deleted.

112 changes: 112 additions & 0 deletions test/test_mechanize.rb
Expand Up @@ -317,6 +317,79 @@ def test_get_file
assert_equal(content_length.to_i, page_as_string.length.to_i)
end

def test_get_follow_meta_refresh
@agent.follow_meta_refresh = true

page = @agent.get('http://localhost/tc_follow_meta.html')

assert_equal(2, @agent.history.length)

assert_equal('http://localhost/tc_follow_meta.html',
@agent.history.first.uri.to_s)
assert_equal('http://localhost/index.html', page.uri.to_s)
assert_equal('http://localhost/index.html', @agent.history.last.uri.to_s)
end

def test_get_follow_meta_refresh_disabled
page = @agent.get('http://localhost/tc_follow_meta.html')
assert_equal('http://localhost/tc_follow_meta.html', page.uri.to_s)
assert_equal(1, page.meta.length)
end

def test_get_follow_meta_refresh_empty_url
@agent.follow_meta_refresh = true

page = @agent.get('http://localhost/refresh_with_empty_url')

assert_equal(3, @agent.history.length)
assert_equal('http://localhost/refresh_with_empty_url',
@agent.history[0].uri.to_s)
assert_equal('http://localhost/refresh_with_empty_url',
@agent.history[1].uri.to_s)
assert_equal('http://localhost/index.html', page.uri.to_s)
assert_equal('http://localhost/index.html', @agent.history.last.uri.to_s)
end

def test_get_follow_meta_refresh_in_body
@agent.follow_meta_refresh = true
requests = []
@agent.pre_connect_hooks << lambda { |_, request|
requests << request
}

@agent.get('http://localhost/tc_meta_in_body.html')
assert_equal 1, requests.length
end

def test_get_follow_meta_refresh_no_url
@agent.follow_meta_refresh = true

page = @agent.get('http://localhost/refresh_without_url')

assert_equal(3, @agent.history.length)
assert_equal('http://localhost/refresh_without_url',
@agent.history[0].uri.to_s)
assert_equal('http://localhost/refresh_without_url',
@agent.history[1].uri.to_s)
assert_equal('http://localhost/index.html', page.uri.to_s)
assert_equal('http://localhost/index.html', @agent.history.last.uri.to_s)
end

def test_get_follow_meta_refresh_referer_not_sent
@agent.follow_meta_refresh = true

requests = []

@agent.pre_connect_hooks << lambda { |_, request|
requests << request
}

@agent.get('http://localhost/tc_follow_meta.html')

assert_equal 2, @agent.history.length
assert_nil requests.last['referer']
end

def test_get_gzip
page = @agent.get("http://localhost/gzip?file=index.html")

Expand All @@ -325,6 +398,31 @@ def test_get_gzip
assert_match('Hello World', page.body)
end

def test_get_http_refresh
@agent.follow_meta_refresh = true
page = @agent.get('http://localhost/http_refresh?refresh_time=0')
assert_equal('http://localhost/index.html', page.uri.to_s)
assert_equal(2, @agent.history.length)
end

def test_get_http_refresh_delay
@agent.follow_meta_refresh = true
class << @agent
attr_accessor :slept
def sleep *args
@slept = args
end
end

@agent.get('http://localhost/http_refresh?refresh_time=1')
assert_equal [1], @agent.slept
end

def test_get_http_refresh_disabled
page = @agent.get('http://localhost/http_refresh?refresh_time=0')
assert_equal('http://localhost/http_refresh?refresh_time=0', page.uri.to_s)
end

def test_get_kcode
$KCODE = 'u'
page = @agent.get("http://localhost/?a=#{[0xd6].pack('U')}")
Expand All @@ -346,6 +444,20 @@ def test_get_redirect
assert_equal 'GET', page.header['X-Request-Method']
end

def test_get_redirect_found
page = @agent.get('http://localhost/response_code?code=302&ct=test/xml')

assert_equal('http://localhost/index.html', page.uri.to_s)

assert_equal(2, @agent.history.length)
end

def test_get_redirect_infinite
assert_raises(Mechanize::RedirectLimitReachedError) {
@agent.get('http://localhost/infinite_refresh')
}
end

def test_get_referer
request = nil
@agent.pre_connect_hooks << lambda { |_, req|
Expand Down

0 comments on commit b37bd3c

Please sign in to comment.