File: spec_helper.rb

package info (click to toggle)
chake 0.93.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 412 kB
  • sloc: ruby: 1,276; sh: 112; makefile: 5; sed: 3
file content (64 lines) | stat: -rw-r--r-- 1,672 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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