-
Notifications
You must be signed in to change notification settings - Fork 2
/
eggs.rb
113 lines (96 loc) · 2.28 KB
/
eggs.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# TODO should this depend on Microsoft::Scripting::Silverlight at all?
include Microsoft::Scripting::Silverlight
SILVERLIGHT = true
#
# 'bacon' is the spec framework used for the tests
#
$:.unshift "#{File.dirname(__FILE__)}/eggs/lib/bacon/lib"
require 'bacon'
#
# Helper for running python code from Ruby
#
$:.unshift "#{File.dirname(__FILE__)}/eggs"
begin
require 'python'
rescue
# ignore
end
#
# TODO better way to redirect output?
#
class IO
def write(str)
Repl.current.output_buffer.write(str)
end
end
class Eggs
class << self
def at_exit_blocks
@at_exit_blocks ||= []
@at_exit_blocks
end
def at_exit_blocks=(value)
@at_exit_blocks = value
end
def execute_at_exit_blocks
while !at_exit_blocks.empty?
at_exit_blocks.pop.call
end
end
def config(options = {})
@config = options
end
def get_config
@config
end
def run(engine = nil)
# eggs_config should call something like Eggs.config(:tests => ['sample'])
load 'eggs_config.rb'
engine ? Repl.show(engine, engine.create_scope) : Repl.show
Repl.current.input_buffer.write "Eggs.current.run_tests\n"
end
def current
@instance ||= Eggs.new
end
end
#
# Test Running
#
def run_tests
Eggs.get_config.each do |test_type, test_files|
test_files.each do |file|
loaded = false
["#{test_type}/#{file}_test.rb", "#{test_type}/test_#{file}.rb"].each do |pth|
prepend = File.dirname(
DynamicApplication.current ?
DynamicApplication.current.entry_point.to_s :
''
)
pth = "#{prepend}/#{pth}" if prepend != '.'
if !loaded && Package.get_file(pth)
load pth
loaded = true
end
end
raise "#{file} is not a known test (check your eggs_config.rb file)" unless loaded
end
end
Eggs.execute_at_exit_blocks
end
end
#
# Redefine at_exit to simply collect the blocks passed to it
#
Eggs.at_exit_blocks = []
module Kernel
def at_exit(&block)
Eggs.at_exit_blocks.push block
end
end
Bacon.summary_on_exit
#
# 'mocha' is the mocking framework used for the tests
#
# Commented out since it's not being used
#$: << "lib/mocha/lib"
#require 'mocha_standalone'