forked from clarete/s3sync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspec_helper.rb
55 lines (43 loc) · 925 Bytes
/
spec_helper.rb
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
require 'fileutils'
require 'simplecov'
SimpleCov.start
def fixture *args
File.join File.dirname(__FILE__), "fixtures", *args
end
def directory path
full = fixture(path)
FileUtils::mkdir_p full
return full
end
def file *args
file = File.join(*args[0..-2])
directory File.dirname(file)
File.open(file, 'w') {|f| f.write args[-1] }
return file
end
def rm path
FileUtils::rm_rf path
end
RSpec::Matchers.define :match_stdout do |check|
@capture = nil
match do |block|
begin
stdout_saved = $stdout
$stdout = StringIO.new
block.call
ensure
@capture = $stdout
$stdout = stdout_saved
end
@capture.string.match check
end
failure_message_for_should do
"expected to #{description}"
end
failure_message_for_should_not do
"expected not to #{description}"
end
description do
"match [#{check}] on stdout [#{@capture.string}]"
end
end