spec/link-checker_spec.rb in link-checker-0.4.0 vs spec/link-checker_spec.rb in link-checker-0.5.0
- old
+ new
@@ -73,68 +73,86 @@
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'] }
- LinkChecker.stub(:external_link_uri_strings).and_return(['http://something.com'])
+ LinkChecker.stub(:external_link_uri_strings).and_return(
+ ['http://something.com', 'http://something-else.com'])
end
it "prints green when the links are good." do
LinkChecker.stub(:check_uri) do
LinkChecker::Good.new(:uri_string => 'http://something.com')
end
$stdout.should_receive(:puts).with(/Checked/i).once
- LinkChecker.new(:target => @site_path).check_uris
+ LinkChecker.new(:target => @site_path).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.'
)
end
$stdout.should_receive(:puts).with(/Problem/i).once
- $stdout.should_receive(:puts).with(/Link/i).once
- $stdout.should_receive(:puts).with(/Response/i).once
- LinkChecker.new(:target => @site_path).check_uris
+ $stdout.should_receive(:puts).with(/Link/i).twice
+ $stdout.should_receive(:puts).with(/Response/i).twice
+ 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).once
- $stdout.should_receive(:puts).with(/Redirected/i).once
- LinkChecker.new(:target => @site_path).check_uris
+ $stdout.should_receive(:puts).with(/Warning/i).twice
+ $stdout.should_receive(:puts).with(/Redirected/i).twice
+ 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
+ LinkChecker.new(
+ :target => @site_path,
+ :options => { :warnings_are_errors => true }
+ ).check_uris.should == 1 # Return value: error
+ end
+
it "does not print warnings when the links redirect with the --no-warnings option." do
LinkChecker.stub(:check_uri) do
LinkChecker::Redirect.new(
:uri_string => 'http://something.com',
- :final_desination => 'http://something-else.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).once
- $stdout.should_receive(:puts).with(/Redirected/i).once
- LinkChecker.new(:target => @site_path).check_uris
+ $stdout.should_receive(:puts).with(/Warning/i).twice
+ $stdout.should_receive(:puts).with(/Redirected/i).twice
+ 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'])
+ 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).once
- $stdout.should_receive(:puts).with(/Response/i).once
+ $stdout.should_receive(:puts).with(/Link/i).twice
+ $stdout.should_receive(:puts).with(/Response/i).twice
thread = LinkChecker.new(:target => @site_path).start_link_check_thread('<html></html>', 'source.html')
thread.join
end
end
\ No newline at end of file