aboutsummaryrefslogtreecommitdiffstats
path: root/switchtower/test/utils.rb
blob: 4ddfbdbad14a65c28b6067175f14c054cde57d8a (plain) (blame)
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
class Module
  def const_during(constant, value)
    if const_defined?(constant)
      overridden = true
      saved = const_get(constant)
      remove_const(constant)
    end

    const_set(constant, value)
    yield
  ensure
    if overridden
      remove_const(constant)
      const_set(constant, saved)
    end
  end
end

class MockLogger
  def info(msg,pfx=nil) end
  def debug(msg,pfx=nil) end
end

class MockConfiguration < Hash
  def initialize(*args)
    super
    self[:release_path] = "/path/to/releases/version"
  end

  def logger
    @logger ||= MockLogger.new
  end

  def method_missing(sym, *args)
    if args.length == 0
      self[sym]
    else
      super
    end
  end
end