require "spec_helper" describe JekyllRedirectFrom::RedirectPage do let(:redirect_page) { described_class.new(@site, @site.source, "posts/12435151125", "larry-had-a-little-lamb") } let(:item_url) { File.join(@site.config["url"], "2014", "01", "03", "moving-to-jekyll.md") } let(:page_content) { redirect_page.generate_redirect_content(item_url) } context "#generate_redirect_content" do it "sets the #content to the generated refresh page" do expect(page_content).to eq(" \n \n \n Redirecting...\n \n \n \n \n \n

Redirecting...

\n

Click here if you are not redirected.

\n \n \n \n") end it "contains the meta refresh tag" do expect(page_content).to include("") end it "contains JavaScript redirect" do expect(page_content).to include("document.location.href = \"http://jekyllrb.com/2014/01/03/moving-to-jekyll.md\";") end it "contains canonical link in header" do expect(page_content).to include("") end it "contains a clickable link to redirect" do expect(page_content).to include("Click here if you are not redirected.") end end context "when writing to disk" do let(:redirect_page_full_path) { redirect_page.destination(@site.dest) } before(:each) do redirect_page.generate_redirect_content(item_url) redirect_page.write(@site.dest) end it "fetches the path properly" do expect(redirect_page_full_path).to match /\/spec\/fixtures\/\_site\/posts\/12435151125\/larry-had-a-little-lamb/ end it "is written to the proper location" do expect(File.exist?(redirect_page_full_path)).to be_true end it "writes the context we expect" do expect(File.read(redirect_page_full_path)).to eql(page_content) end end end