Sha256: 6069bc50de7588cf3ac3dd6c894ba69ca432f309ca2b8a7ad679867e18f88080

Contents?: true

Size: 1.67 KB

Versions: 8

Compression:

Stored size: 1.67 KB

Contents

require 'spec_helper'

describe Deplomat::Node do

  before(:each) do
    @fixtures_dir = Dir.pwd + "/spec/fixtures"
    @node = Deplomat::Node.new(logfile: "#{@fixtures_dir}/deplomat.log", log_to: [:file, :stdout])
  end

  it "checks if file exists" do
    expect(@node.file_exists?("#{@fixtures_dir}/existing_file.txt")).to be_falsey
    expect(@node.file_exists?("/non-existent-path")).to be_falsey
    FileUtils.touch("#{@fixtures_dir}/existing_file.txt")
    expect(@node.file_exists?("#{@fixtures_dir}/existing_file.txt")).to be_truthy
    FileUtils.rm("#{@fixtures_dir}/existing_file.txt")
  end

  describe "logging" do

    after(:each) do
      @node.log_to = []
      @node.remove("#{@fixtures_dir}/deplomat.log")
    end

    it "logs to the stdout" do
      expect($stdout).to receive(:print).exactly(4).times
      @node.execute("ls #{@fixtures_dir}/dir1")
    end

    it "logs to a log file" do
      @node.log_to = [:file]
      @node.execute("ls #{@fixtures_dir}/dir1")
      log = File.readlines("#{@fixtures_dir}/deplomat.log")
      expect(log.size).to eq(4)
    end

    it "puts additional messages into the terminal when required" do
      expect($stdout).to receive(:print).once.with("hello\n".white)
      expect($stdout).to receive(:print).once.with("--> ls #{@fixtures_dir}/dir1\n".white)
      expect($stdout).to receive(:print).once.with("  file1\n".light_black)
      expect($stdout).to receive(:print).once.with("  file2\n".light_black)
      expect($stdout).to receive(:print).once.with("  subdir1\n".light_black)
      expect($stdout).to receive(:print).once.with("bye\n".white)
      @node.execute("ls #{@fixtures_dir}/dir1", message: ["hello", "bye"])
    end

  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
deplomat-0.1.13 spec/node_spec.rb
deplomat-0.1.12 spec/node_spec.rb
deplomat-0.1.11 spec/node_spec.rb
deplomat-0.1.10 spec/node_spec.rb
deplomat-0.1.8 spec/node_spec.rb
deplomat-0.1.7 spec/node_spec.rb
deplomat-0.1.6 spec/node_spec.rb
deplomat-0.1.5 spec/node_spec.rb