Sha256: 359b4abd7f07a84f93faa1c127a7948fa71b507a06af128ca3187cb92db6dfde

Contents?: true

Size: 1.63 KB

Versions: 9

Compression:

Stored size: 1.63 KB

Contents

begin
  require 'simplecov'
  SimpleCov.start do
    minimum_coverage 35.3
    track_files 'lib/**/*.rb'
    add_filter %r{^/spec/}
    add_filter %r{^/lib/chake/config_manager/skel/}
  end
rescue LoadError
  puts "W: simplecov not installed, we won't have a coverage report"
end

require 'chake/node'
require 'chake/connection'

require 'rspec/version'
if RSpec::Version::STRING < '2.14'
  puts 'Skipping tests, need RSpec >= 2.14'
  exit
end

shared_examples 'Chake::Connection' do |connection_class|
  let(:connection) { connection_class.new(node) }

  it('runs commands') do
    io = StringIO.new("line 1\n  line 2\n")
    expect(IO).to receive(:popen).with(connection.command_runner + ['/bin/sh'], 'w+', Hash).and_return(io)
    expect(io).to receive(:write).with('something').ordered
    expect(io).to receive(:close_write).ordered
    expect(node).to receive(:log).with('$ something')
    expect(node).to receive(:log).with('line 1')
    expect(node).to receive(:log).with('  line 2')
    connection.run('something')
  end

  it('runs as root') do
    expect(connection).to receive(:run).with('sudo something')
    connection.run_as_root('something')
  end

  it('does not use sudo if already root') do
    allow(connection.node).to receive(:remote_username).and_return('root')
    expect(connection).to receive(:run).with('something')
    connection.run_as_root('something')
  end
end

module Helpers
  def silence(stream)
    orig_stream = stream.clone
    begin
      File.open('/dev/null', 'w') do |f|
        stream.reopen(f)
        yield
      end
    ensure
      stream.reopen(orig_stream)
    end
  end
end

RSpec.configure do |c|
  c.include Helpers
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
chake-0.92 spec/spec_helper.rb
chake-0.91 spec/spec_helper.rb
chake-0.90.3 spec/spec_helper.rb
chake-0.90.2 spec/spec_helper.rb
chake-0.90.1 spec/spec_helper.rb
chake-0.90 spec/spec_helper.rb
chake-0.82 spec/spec_helper.rb
chake-0.81.1 spec/spec_helper.rb
chake-0.81 spec/spec_helper.rb