Sha256: c2e53efe4497f5203fa5b341bd2d05c5d30676c474c4e1d7ca613c326fd35097

Contents?: true

Size: 1.55 KB

Versions: 3

Compression:

Stored size: 1.55 KB

Contents

require 'spec_helper'

describe Rpub::Commands::Generate do
  let(:buffer) { StringIO.new }
  before do
    Dir.chdir File.join(FIXTURES_DIRECTORY, 'generate')
  end

  after do
    File.unlink 'styles.css' if File.exist?('styles.css')
    File.unlink 'layout.html' if File.exist?('layout.html')
    File.unlink 'config.yml' if File.exist?('config.yml')
  end

  context 'given a specific option' do
    let(:subject) { described_class.new(['--config'], buffer) }

    it 'should generate one file' do
      expect(&subject.method(:invoke)).to create_file('config.yml')
    end

    it 'should not generate stylesheet' do
      expect(&subject.method(:invoke)).to_not create_file('layout.html', 'styles.css')
    end
  end

  context 'given a no option' do
    let(:subject) { described_class.new(['--no-styles'], buffer) }

    it 'should generate two files' do
      expect(&subject.method(:invoke)).to create_file('layout.html', 'config.yml')
    end

    it 'should not generate stylesheet' do
      expect(&subject.method(:invoke)).to_not create_file('styles.css')
    end
  end

  context 'given no options' do
    let(:subject) { described_class.new([], buffer) }

    it 'should generate three files' do
      expect(&subject.method(:invoke)).to create_file('styles.css', 'layout.html', 'config.yml')
    end

    it 'should not generate existing files' do
      File.open('styles.css', 'w') { |f| f.write 'foo' }
      expect(&subject.method(:invoke)).to_not change { File.read('styles.css') }
      buffer.string.should include('Not overriding styles.css')
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rpub-0.4.0 spec/rpub/commands/generate_spec.rb
rpub-0.3.0 spec/rpub/commands/generate_spec.rb
rpub-0.2.1 spec/rpub/commands/generate_spec.rb