-
Notifications
You must be signed in to change notification settings - Fork 36
/
spec_helper.rb
96 lines (76 loc) · 1.81 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
require "rake-pipeline"
require "rake-pipeline-web-filters"
class Rake::Pipeline
module SpecHelpers
class MemoryFileWrapper < Struct.new(:root, :path, :encoding, :body)
@@files = {}
def self.files
@@files
end
def with_encoding(new_encoding)
self.class.new(root, path, new_encoding, body)
end
def fullpath
File.join(root, path)
end
def create
@@files[fullpath] = self
self.body = ""
yield
end
alias read body
def write(contents)
self.body << contents
end
end
# TODO: OS agnostic modules
module FileUtils
def mkdir_p(dir)
system "mkdir", "-p", dir
end
def touch(file)
system "touch", file
end
def rm_rf(dir)
system "rm", "-rf", dir
end
def touch_p(file)
dir = File.dirname(file)
mkdir_p dir
touch file
end
def age_existing_files
old_time = Time.now - 10
Dir[File.join(tmp, "**/*.js")].each do |file|
File.utime(old_time, old_time, file)
end
end
end
module Filters
ConcatFilter = Rake::Pipeline::ConcatFilter
MemoryFileWrapper = Rake::Pipeline::SpecHelpers::MemoryFileWrapper
class StripAssertsFilter < Rake::Pipeline::Filter
def generate_output(inputs, output)
inputs.each do |input|
output.write input.read.gsub(%r{^\s*assert\(.*\)\s*;?\s*$}m, '')
end
end
end
end
end
end
RSpec.configure do |config|
original = Dir.pwd
config.include Rake::Pipeline::SpecHelpers::FileUtils
def tmp
File.expand_path("../tmp", __FILE__)
end
config.before do
rm_rf(tmp)
mkdir_p(tmp)
Dir.chdir(tmp)
end
config.after do
Dir.chdir(original)
end
end