require 'rails_helper' require_dependency 'retrieve_title' describe RetrieveTitle do context "extract_title" do it "will extract the value from the title tag" do title = RetrieveTitle.extract_title( "My Cool Title" ) expect(title).to eq("My Cool Title") end it "will strip whitespace" do title = RetrieveTitle.extract_title( " Another Title\n\n " ) expect(title).to eq("Another Title") end it "will pick og:title if title is missing" do title = RetrieveTitle.extract_title(<<~HTML HTML ) expect(title).to eq("Good Title") end it "will prefer the title from an opengraph tag" do title = RetrieveTitle.extract_title(<<~HTML Good Title HTML ) expect(title).to eq("Good Title") end it "will parse a YouTube url from javascript" do title = RetrieveTitle.extract_title(<<~HTML YouTube HTML ) expect(title).to eq("Video Title") end end end