Sha256: 1568749a6332fce3b644adbf7290c0e8107ab69f7c5135c34d5e82a08c03d64e

Contents?: true

Size: 1.65 KB

Versions: 14

Compression:

Stored size: 1.65 KB

Contents

require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")

describe "visit" do
  before do
    with_html <<-HTML
      <html>
      Hello world
      </html>
    HTML
  end

  it "should use get" do
    webrat_session.should_receive(:get).with("/", {})
    visit("/")
  end

  it "should assert valid response" do
    webrat_session.response_code = 501
    lambda { visit("/") }.should raise_error(Webrat::PageLoadError)
  end

  [200, 300, 400, 499].each do |status|
    it "should consider the #{status} status code as success" do
      webrat_session.stub!(:redirect? => false)
      webrat_session.response_code = status
      lambda { visit("/") }.should_not raise_error
    end
  end

  it "should require a visit before manipulating page" do
    lambda { fill_in "foo", :with => "blah" }.should raise_error(Webrat::WebratError)
  end

  it "should follow internal redirects" do
    webrat_session.should_receive(:internal_redirect?).twice.and_return(true, false)
    webrat_session.response.should_receive(:headers).once.and_return({ "Location" => "/newurl" })

    visit("/oldurl")

    current_url.should == "/newurl"
  end

  it "should not follow external redirects" do
    webrat_session.should_receive(:internal_redirect?).and_return(false)

    visit("/oldurl")

    current_url.should == "/oldurl"
  end
end

describe "visit with referer" do
  before do
    webrat_session.instance_variable_set(:@current_url, "/old_url")
    with_html <<-HTML
      <html>
      Hello world
      </html>
    HTML
  end

  it "should use get with referer header" do
    webrat_session.should_receive(:get).with("/", {}, {"HTTP_REFERER" => "/old_url"})
    visit("/")
  end

end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
adva-0.3.2 test/webrat/spec/public/visit_spec.rb
adva-0.3.1 test/webrat/spec/public/visit_spec.rb
adva-0.3.0 test/webrat/spec/public/visit_spec.rb
adva-0.2.4 test/webrat/spec/public/visit_spec.rb
adva-0.2.3 test/webrat/spec/public/visit_spec.rb
adva-0.2.2 test/webrat/spec/public/visit_spec.rb
adva-0.2.1 test/webrat/spec/public/visit_spec.rb
adva-0.2.0 test/webrat/spec/public/visit_spec.rb
adva-0.1.4 test/webrat/spec/public/visit_spec.rb
adva-0.1.3 test/webrat/spec/public/visit_spec.rb
adva-0.1.2 test/webrat/spec/public/visit_spec.rb
adva-0.1.1 test/webrat/spec/public/visit_spec.rb
adva-0.1.0 test/webrat/spec/public/visit_spec.rb
adva-0.0.1 test/webrat/spec/public/visit_spec.rb