spec/link-checker_spec.rb in link-checker-0.5.2 vs spec/link-checker_spec.rb in link-checker-0.6.0

- old
+ new

@@ -9,22 +9,22 @@ @site_path = 'spec/test-site/public/' end it "finds all of the HTML files in the target path." do files = LinkChecker.new(:target => @site_path).html_file_paths - files.size.should == 3 + files.size.should == 4 end it "finds all of the external links in an HTML file." do links = LinkChecker.external_link_uri_strings( - open('spec/test-site/public/blog/2012/10/02/a-list-of-links/index.html')) + open('spec/test-site/public/blog/2012/10/07/some-good-links/index.html')) links.size.should == 4 end it "finds all of the external links in a string." do links = LinkChecker.external_link_uri_strings( - open('spec/test-site/public/blog/2012/10/02/a-list-of-links/index.html').read) + open('spec/test-site/public/blog/2012/10/07/some-good-links/index.html').read) links.size.should == 4 end end @@ -72,59 +72,68 @@ describe "scans a file path and prints output" do before(:each) do LinkChecker.any_instance.stub(:html_file_paths) { - ['spec/test-site/public/blog/2012/10/02/a-list-of-links/index.html'] } + ['spec/test-site/public/blog/2012/10/07/some-good-links/index.html'] } LinkChecker.stub(:external_link_uri_strings).and_return( - ['http://something.com', 'http://something-else.com']) + (1..20).map{|i| "http://something-#{i}.com" } ) end it "prints green when the links are good." do LinkChecker.stub(:check_uri) do + sleep 0.5 # Make LinkChecker#wait_to_spawn_thread wait a little. LinkChecker::Good.new(:uri_string => 'http://something.com') end - $stdout.should_receive(:puts).with(/Checked/i).once - LinkChecker.new(:target => @site_path).check_uris.should == 0 # Return value: good + $stdout.should_receive(:puts).with(/Checked\: .*\.html/).once + $stdout.should_receive(:puts).with(/Checked 20 links in 1 HTML file and found no errors/) + LinkChecker.new( + :target => @site_path, + # This is to make sure that the entire LinkChecker#wait_to_spawn_thread gets hit during testing. + :options => { :max_threads => 1 } + ).check_uris.should == 0 # Return value: good end it "prints red when the links are bad." do LinkChecker.stub(:check_uri) do LinkChecker::Error.new( :uri_string => 'http://something.com', - :response => 'No.' + :error => 'No.' ) end - $stdout.should_receive(:puts).with(/Problem/i).once - $stdout.should_receive(:puts).with(/Link/i).twice - $stdout.should_receive(:puts).with(/Response/i).twice + $stdout.should_receive(:puts).with(/Problem\: .*\.html/).once + $stdout.should_receive(:puts).with(/Link\: http/).exactly(20).times + $stdout.should_receive(:puts).with(/Response/).exactly(20).times + $stdout.should_receive(:puts).with(/Checked 20 links in 1 HTML file and found 20 errors/) LinkChecker.new(:target => @site_path).check_uris.should == 1 # Return value: error end it "prints yellow warnings when the links redirect." do LinkChecker.stub(:check_uri) do LinkChecker::Redirect.new( :uri_string => 'http://something.com', :final_desination => 'http://something-else.com' ) end - $stdout.should_receive(:puts).with(/Checked/i).once - $stdout.should_receive(:puts).with(/Warning/i).twice - $stdout.should_receive(:puts).with(/Redirected/i).twice + $stdout.should_receive(:puts).with(/Checked\: .*\.html/).once + $stdout.should_receive(:puts).with(/Warning/).exactly(20).times + $stdout.should_receive(:puts).with(/Redirected/).exactly(20).times + $stdout.should_receive(:puts).with(/Checked 20 links in 1 HTML file and found no errors/) LinkChecker.new(:target => @site_path).check_uris.should == 0 # Return value: good end it "prints errors when there are warnings with the --warnings_are_errors option." do LinkChecker.stub(:check_uri) do LinkChecker::Redirect.new( :uri_string => 'http://something.com', :final_destination_uri_string => 'http://something-else.com' ) end - $stdout.should_receive(:puts).with(/Problem/i).once - $stdout.should_receive(:puts).with(/Link/i).twice - $stdout.should_receive(:puts).with(/Redirected/i).twice + $stdout.should_receive(:puts).with(/Problem\: .*\.html/).once + $stdout.should_receive(:puts).with(/Link/).exactly(20).times + $stdout.should_receive(:puts).with(/Redirected/).exactly(20).times + $stdout.should_receive(:puts).with(/Checked 20 links in 1 HTML file and found 20 errors/) LinkChecker.new( :target => @site_path, :options => { :warnings_are_errors => true } ).check_uris.should == 1 # Return value: error end @@ -134,26 +143,27 @@ LinkChecker::Redirect.new( :uri_string => 'http://something.com', :final_destination_uri_string => 'http://something-else.com' ) end - $stdout.should_receive(:puts).with(/Checked/i).once - $stdout.should_receive(:puts).with(/Warning/i).twice - $stdout.should_receive(:puts).with(/Redirected/i).twice + $stdout.should_receive(:puts).with(/Checked\: .*\.html/).once + $stdout.should_receive(:puts).with(/Warning/).exactly(20).times + $stdout.should_receive(:puts).with(/Redirected/).exactly(20).times + $stdout.should_receive(:puts).with(/Checked 20 links in 1 HTML file and found no errors/) LinkChecker.new(:target => @site_path).check_uris.should == 0 # Return value: good end end describe "prints output for invalid links and" do it "declares them to be bad." do LinkChecker.stub(:external_link_uri_strings).and_return( ['hQQp://!!!.com', 'hOOp://???.com']) - $stdout.should_receive(:puts).with(/Problem/i).once - $stdout.should_receive(:puts).with(/Link/i).twice - $stdout.should_receive(:puts).with(/Response/i).twice + $stdout.should_receive(:puts).with(/Problem\: .*\.html/).once + $stdout.should_receive(:puts).with(/Link/).twice + $stdout.should_receive(:puts).with(/Response/).twice thread = LinkChecker.new(:target => @site_path).start_link_check_thread('<html></html>', 'source.html') thread.join end end @@ -162,10 +172,11 @@ FakeWeb.register_uri(:any, 'http://some-target.com', :body => "Yay it worked.") LinkChecker.stub(:external_link_uri_strings).and_return(['http://something.com']) LinkChecker.stub(:check_uri) do LinkChecker::Good.new(:uri_string => 'http://something.com') end - $stdout.should_receive(:puts).with(/Checked/i).once + $stdout.should_receive(:puts).with(/Checked\: http/).once + $stdout.should_receive(:puts).with(/Checked 1 link in 1 HTML file and found no errors/) LinkChecker.new(:target => 'http://some-target.com').check_uris end describe "produces useful return codes when" do \ No newline at end of file