Sha256: 6313bcd6c130cafdf76d18b8866ae6547045cbabef15270f0d733848155ad997

Contents?: true

Size: 1.85 KB

Versions: 2

Compression:

Stored size: 1.85 KB

Contents

require 'spec_helper'

describe WP2Middleman::Migrator do
  let(:file) { 'spec/fixtures/fixture.xml' }
  let(:migrator) { WP2Middleman::Migrator.new(file) }

  it "exists as a class within the WP2Middleman module" do
    expect(WP2Middleman::Migrator.class).to eq Class
  end

  describe "#migrate" do
    before :each do
      allow(FileUtils).to receive(:mkdir_p)
      allow(File).to receive(:write)
    end

    it "ensures there is an export directory" do
      allow(File).to receive(:open)

      expect(migrator).to receive :ensure_export_directory

      migrator.migrate
    end

    it "writes a middleman markdown file for each post" do
      expect(File).to receive(:write).exactly(4).times

      migrator.migrate
    end

    it "writes the proper markdown file" do
      post = migrator.posts.first

      allow(post).to receive(:file_content) { "content" }
      allow(migrator).to receive(:valid_posts) { [post] }

      expect(File).to receive(:write).with("#{Dir.pwd}/export/2012-06-08-A-Title.html.markdown", "content")

      migrator.migrate
    end
  end

  describe "#output_path" do
    subject { migrator.output_path }

    let(:export_path) { migrator.output_path }

    it "reports the proper path to the export directory" do
      expect(export_path).to eq "#{Dir.pwd}/export/"
    end
  end

  describe "#ensure_export_directory" do
    it "makes the export directory if it's not already there" do
      allow(File).to receive(:directory?) { false }

      expect(FileUtils).to receive(:mkdir_p).with("#{Dir.pwd}/export/")

      migrator.ensure_export_directory
    end

    context "the export directory is already there" do
      it "does not create it" do
        allow(File).to receive(:directory?) { true }

        migrator.ensure_export_directory

        expect(FileUtils).not_to receive(:mkdir_p).with("#{Dir.pwd}/export/")
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
wp2middleman-0.0.3 spec/lib/wp2middleman/migrator_spec.rb
wp2middleman-0.0.2 spec/lib/wp2middleman/migrator_spec.rb