This repository has been archived by the owner on Aug 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
/
helper.rb
58 lines (45 loc) · 1.51 KB
/
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
require "rubygems"
require "test/unit"
%w(../lib ../ext/spidermonkey).each do |path|
$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), path)))
end
# If the test isn't running from Rake, make sure the extension's current.
Rake rescue Dir.chdir(File.dirname(__FILE__) + "/..") { %x(rake extensions) }
require "johnson"
module Johnson
class TestCase < Test::Unit::TestCase
class TestLogger
def debug(string)
puts string
end
end
undef :default_test if method_defined? :default_test
def setup
@runtime = Johnson::Runtime.new
#@runtime.delegate.gc_zeal = 2
#@runtime.delegate.debugger = Johnson::SpiderMonkey::Debugger.new(TestLogger.new)
end
def assert_js(expression, options={})
runtime = options[:runtime] || @runtime
assert(runtime.evaluate(expression), "Expected JS expression [#{expression}] to be true.")
end
def assert_js_equal(expected, expression, options={})
runtime = options.delete(:runtime) || @runtime
options.each { |k, v| runtime[k.to_s] = v }
assert_equal(expected, runtime.evaluate(expression))
end
end
class NodeTestCase < Test::Unit::TestCase
include Johnson::Nodes
undef :default_test if method_defined? :default_test
def setup
@parser = Johnson::Parser
end
def assert_sexp(expected, actual)
assert_equal(expected, actual.to_sexp)
end
def assert_ecma(expected, actual)
assert_equal(expected, actual.to_ecma)
end
end
end