Statistics
| Branch: | Tag: | Revision:

one / share / hooks / spec / SystemMock.rb @ 3113f007

History | View | Annotate | Download (715 Bytes)

1
module SystemMock
2
    require 'open3'
3
    def execute_cmd(cmd)
4
        if $capture_commands
5
            $capture_commands.each do |regex, output|
6
                if cmd.match(regex)
7
                    return output
8
                end
9
            end
10
        end
11
        Open3.popen3(cmd){|stdin, stdout, stderr| stdout.read}
12
    end
13

    
14
    def `(cmd)
15
        log_command(:backtick, cmd)
16
        execute_cmd(cmd)
17
    end
18

    
19
    def system(cmd)
20
        log_command(:system, cmd)
21
        execute_cmd(cmd)
22
        nil
23
    end
24

    
25
    def log_command(facility, msg)
26
        $collector = Hash.new if !$collector
27
        $collector[facility] = Array.new if !$collector[facility]
28
        $collector[facility] << msg
29
    end
30
end