Sha256: d3f07aa15814d5b669cb88d09ac27e3e03cf0aac14bdcc637ddf982fddf9b9c6

Contents?: true

Size: 1.19 KB

Versions: 8

Compression:

Stored size: 1.19 KB

Contents

require 'epitools/browser'

class Mechanize::Page
  def url
    uri.to_s
  end
end



describe Browser do

  before :all do
    @browser = Browser.new
  end

  after :all do
    @browser.cache.delete!
  end

  it "googles" do
    page = @browser.get("http://google.com")
    page.body["Feeling Lucky"].should_not be_empty
  end
  
  it "googles (cached)" do
    @browser.get("http://google.com").body
  end

end



describe Browser::Cache do

  before :all do
    @agent = Mechanize.new
    Browser::Cache.new(@agent).delete!
    @cache = Browser::Cache.new(@agent)
  end

  def new_page(body, url)
    Mechanize::Page.new(
      URI.parse(url),
      {'content-type'=>'text/html'},
      body,
      nil,
      @agent
    )
  end

  after :all do
    @cache.delete!
  end

  it "writes and reads" do
    body = "Blah blah blah."
    url  = "http://example.com/url.html"

    page = new_page(body, url)

    page.body.should == body
    page.url.should == url

    @cache.put page, url
    @cache.urls.size.should == 1
    @cache.includes?(url).should == true

    result = @cache.get url

    body.should == page.body
    body.should == result.body
    url.should == page.url
    url.should == result.url
  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
epitools-0.4.20 spec/browser_spec.rb
epitools-0.4.19 spec/browser_spec.rb
epitools-0.4.18 spec/browser_spec.rb
epitools-0.4.17 spec/browser_spec.rb
epitools-0.4.16 spec/browser_spec.rb
epitools-0.4.15 spec/browser_spec.rb
epitools-0.4.14 spec/browser_spec.rb
epitools-0.4.13 spec/browser_spec.rb