Skip to content
Browse files

page specs

  • Loading branch information...
1 parent 2137c1b commit ba35e18a1f6a4a8dc9d4c3604616f3434c262f4a @chriskite chriskite committed Jul 23, 2009
Showing with 50 additions and 1 deletion.
  1. +1 −1 spec/anemone_spec.rb
  2. +49 −0 spec/page_spec.rb
View
2 spec/anemone_spec.rb
@@ -8,7 +8,7 @@
end
it "should have options" do
- Anemone.respond_to?('options').should == true
+ Anemone.should respond_to(:options)
end
it "should accept options for the crawl" do
View
49 spec/page_spec.rb
@@ -0,0 +1,49 @@
+require File.dirname(__FILE__) + '/spec_helper'
+
+module Anemone
+ describe Page do
+
+ before(:each) do
+ @page = Page.fetch(FakePage.new('home').url)
+ end
+
+ it "should be able to fetch a page" do
+ @page.should_not be_nil
+ @page.url.to_s.should include('home')
+ end
+
+ it "should store the response headers when fetching a page" do
+ @page.headers.should_not be_nil
+ @page.headers.should have_key('content-type')
+ end
+
+ it "should have an OpenStruct attribute for the developer to store data in" do
+ @page.data.should_not be_nil
+ @page.data.should be_an_instance_of(OpenStruct)
+
+ @page.data.test = 'test'
+ @page.data.test.should == 'test'
+ end
+
+ it "should have a Nokogori::HTML::Document attribute for the page body" do
+ @page.doc.should_not be_nil
+ @page.doc.should be_an_instance_of(Nokogiri::HTML::Document)
+ end
+
+ it "should indicate whether it was fetched after an HTTP redirect" do
+ @page.should respond_to(:redirect?)
+
+ @page.redirect?.should == false
+
+ Page.fetch(FakePage.new('redir', :redirect => 'home').url).redirect?.should == true
+ end
+
+ it "should have a method to tell if a URI is in the same domain as the page" do
+ @page.should respond_to(:in_domain?)
+
+ @page.in_domain?(URI(FakePage.new('test').url)).should == true
+ @page.in_domain?(URI('http://www.other.com/')).should == false
+ end
+
+ end
+end

0 comments on commit ba35e18

Please sign in to comment.
Something went wrong with that request. Please try again.