spec/document_spec.rb in metainspector-3.1.1 vs spec/document_spec.rb in metainspector-3.2.0

- old
+ new

@@ -87,16 +87,63 @@ tar_url = MetaInspector::Document.new('http://pagerankalert.com/file.tar.gz', html_content_only: true, exception_log: logger) tar_url.title end + + context 'when a warn_level of :store is passed in' do + before do + @bad_request = MetaInspector::Document.new('http://pagerankalert.com/image.png', html_content_only: true, warn_level: :store) + @bad_request.title + end + + it 'stores the exceptions' do + @bad_request.exceptions.should_not be_empty + end + + it 'makes ok? to return false' do + @bad_request.should_not be_ok + end + end + + context 'when a warn_level of :warn is passed in' do + before do + $stderr = StringIO.new + end + + after do + $stderr = STDERR + end + + it 'warns on STDERR' do + bad_request = MetaInspector::Document.new('http://pagerankalert.com/image.png', html_content_only: true, warn_level: :warn) + bad_request.title + + $stderr.rewind + $stderr.string.chomp.should eq("The url provided contains image/png content instead of text/html content") + end + + it 'does not raise an exception' do + expect { + bad_request = MetaInspector::Document.new('http://pagerankalert.com/image.png', html_content_only: true, warn_level: :warn) + bad_request.title + }.to_not raise_exception + end + + it 'does not store exceptions' do + bad_request = MetaInspector::Document.new('http://pagerankalert.com/image.png', html_content_only: true, warn_level: :warn) + bad_request.title + + expect( bad_request.exceptions ).to be_empty + end + end end describe 'headers' do it "should include default headers" do url = "http://pagerankalert.com/" expected_headers = {'User-Agent' => "MetaInspector/#{MetaInspector::VERSION} (+https://github.com/jaimeiniesta/metainspector)"} - + headers = {} headers.should_receive(:merge!).with(expected_headers) Faraday::Connection.any_instance.stub(:headers){headers} MetaInspector::Document.new(url) end