-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathexclude_spec.rb
55 lines (44 loc) · 1.62 KB
/
exclude_spec.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
gem 'minitest'
require 'minitest/autorun'
require 'ruby2js/filter/functions'
describe 'Ruby2JS::Filter.exclude' do
def to_js( string, options={} )
_(Ruby2JS.convert(string,
options.merge(filters: [Ruby2JS::Filter::Functions])).to_s)
end
describe 'default exclude' do
it "should default to NOT mapping class to constructor" do
to_js( 'a.class' ).must_equal 'a.class'
end
it "should be able to OPT IN to mapping class to constructor" do
to_js( 'a.class', include: :class ).must_equal 'a.constructor'
end
it "should be able to OPT IN to all mappings" do
to_js( 'a.class', include_all: true ).must_equal 'a.constructor'
end
it "should default to NOT mapping call to direct call" do
to_js( 'a.call(b)' ).must_equal 'a.call(b)'
end
it "should be able to OPT IN to mapping call to direct call" do
to_js( 'a.call(b)', include: [:call] ).must_equal 'a(b)'
end
end
describe 'explicit exclude - send' do
it "should default to mapping to_s to toString" do
to_js( 'a.to_s' ).must_equal 'a.toString()'
end
it "should be able to OPT OUT of mapping to_s to toString" do
to_js( 'a.to_s', exclude: :to_s ).must_equal 'a.to_s'
end
end
describe 'explicit exclude - block' do
it "should default to mapping for setInterval" do
to_js( 'setInterval(500) {nil}' ).
must_equal 'setInterval(function() {null}, 500)'
end
it "should be able to OPT OUT of setInterval mapping" do
to_js( 'setInterval(500) {nil}', exclude: :setInterval ).
must_equal 'setInterval(500, function() {null})'
end
end
end