Sha256: fc6aaf8abbf07db134bd06505787f7e910548cd74381c73803d2d4f7724436f3

Contents?: true

Size: 1.54 KB

Versions: 8

Compression:

Stored size: 1.54 KB

Contents

$:.unshift File.join(File.dirname(__FILE__), "..", "lib")

require 'test/unit'
require 'rubygems'
require 'mechanize'
require 'test_includes'

class ResponseCodeMechTest < Test::Unit::TestCase
  include TestMethods

  def setup
    @agent = WWW::Mechanize.new
  end

  def test_redirect
    @agent.get("http://localhost:#{PORT}/response_code?code=300")
    assert_equal("http://localhost:#{PORT}/index.html",
      @agent.current_page.uri.to_s)

    @agent.get("http://localhost:#{PORT}/response_code?code=301")
    assert_equal("http://localhost:#{PORT}/index.html",
      @agent.current_page.uri.to_s)

    @agent.get("http://localhost:#{PORT}/response_code?code=302")
    assert_equal("http://localhost:#{PORT}/index.html",
      @agent.current_page.uri.to_s)

    @agent.get("http://localhost:#{PORT}/response_code?code=303")
    assert_equal("http://localhost:#{PORT}/index.html",
      @agent.current_page.uri.to_s)

    @agent.get("http://localhost:#{PORT}/response_code?code=307")
    assert_equal("http://localhost:#{PORT}/index.html",
      @agent.current_page.uri.to_s)
  end

  def test_do_not_follow_redirect
    @agent.redirect_ok = false

    @agent.get("http://localhost:#{PORT}/response_code?code=302")
    assert_equal("http://localhost:#{PORT}/response_code?code=302",
      @agent.current_page.uri.to_s)
  end

  def test_error
    @agent = WWW::Mechanize.new
    begin
      @agent.get("http://localhost:#{PORT}/response_code?code=500")
    rescue WWW::Mechanize::ResponseCodeError => err
      assert_equal("500", err.response_code)
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
mechanize-0.6.10 test/tc_response_code.rb
mechanize-0.6.7 test/tc_response_code.rb
mechanize-0.6.5 test/tc_response_code.rb
mechanize-0.6.11 test/tc_response_code.rb
mechanize-0.6.6 test/tc_response_code.rb
mechanize-0.6.8 test/tc_response_code.rb
mechanize-0.6.4 test/tc_response_code.rb
mechanize-0.6.9 test/tc_response_code.rb