/
spec_helper.rb
66 lines (56 loc) · 1.35 KB
/
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
56
57
58
59
60
61
62
63
64
65
66
require 'rspec/fire'
require 'tempfile'
require 'stringio'
require 'rake'
require 'rake/tasklib'
RSpec.configure do |config|
config.include(RSpec::Fire)
def capture_stdout &block
real_stdout, $stdout = $stdout, StringIO.new
yield
$stdout.string
ensure
$stdout = real_stdout
end
end
# Keep a reference to all tempfiles so they are not garbage collected until the
# process exits.
$tempfiles = []
def make_file(content)
tempfile = Tempfile.new('cane')
$tempfiles << tempfile
tempfile.print(content)
tempfile.flush
tempfile.path
end
def in_tmp_dir(&block)
Dir.mktmpdir do |dir|
Dir.chdir(dir, &block)
end
end
RSpec::Matchers.define :have_violation do |label|
match do |check|
violations = check.violations
violations.length.should == 1
violations[0][:label].should == label
end
end
RSpec::Matchers.define :have_no_violations do |label|
match do |check|
violations = check.violations
violations.length.should == 0
end
end
require 'simplecov'
class SimpleCov::Formatter::QualityFormatter
def format(result)
SimpleCov::Formatter::HTMLFormatter.new.format(result)
File.open("coverage/covered_percent", "w") do |f|
f.puts result.source_files.covered_percent.to_i
end
end
end
SimpleCov.formatter = SimpleCov::Formatter::QualityFormatter
SimpleCov.start do
add_filter "vendor/bundle/"
end