Sha256: a5c33e07a373cd3fb1259a44a35bd36f628c87c1bca13f038966c55cb93ef829

Contents?: true

Size: 1.49 KB

Versions: 1

Compression:

Stored size: 1.49 KB

Contents

require 'albacore/cli'

describe Albacore::Cli do

  before :each do
    # Output to a file that doesn't conflict with the project's Rakefile file.
    @test_rake = 'Test_Rakefile'
    @test_gem = 'Test_Gemfile'
    Albacore.stub(:rakefile).and_return @test_rake
    Albacore.stub(:gemfile).and_return @test_gem

    # Capture the output that would typically appear in the console.
    @original_stdout = $stdout
    @output = StringIO.new
    $stdout = @output
  end

  after :each do
    # Delete the Test_Rakefile if one was created.
    FileUtils.rm @test_rake
    FileUtils.rm @test_gem

    # Return output to its original value.
    $stdout = @original_stdout
  end

  %w( init initialize ).each do |command|
    describe command do
      describe 'when no Rakefile file exists' do
        it 'creates a new Rakefile and Gemfile' do
          expect {
            described_class.new [command]
          }.to change{ File.exist?(@test_rake) }.from(false).to(true)
        end
      end
      describe 'when a Rakefile file already exists' do
        before :each do
          FileUtils.touch @test_rake
          FileUtils.touch @test_gem
        end
        it 'outputs a warning message' do
          described_class.new [command]
          @output.string.should match /One of \[.*\] already exists\n/
        end
        it "does not overwrite the existing file" do
          expect {
            described_class.new [command]
          }.to_not change{ File.mtime(@test_rake) }
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
albacore-2.1.1 spec/cli_spec.rb