-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathyield_spec.rb
35 lines (28 loc) · 1.1 KB
/
yield_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
gem 'minitest'
require 'minitest/autorun'
require 'ruby2js/filter/functions'
describe "yield suport" do
def to_js(string)
_(Ruby2JS.convert(string, eslevel: 2015, filters: [Ruby2JS::Filter::Functions]).to_s)
end
describe "yield" do
it "should add implicit block arg" do
to_js( 'def func(); puts "yielding:"; yield; end' ).
must_include 'function func(_implicitBlockYield=null) {console.log("yielding:"); _implicitBlockYield()}'
end
it "should work with existing arguments" do
to_js( 'def func(x); yield; end' ).
must_include 'function func(x, _implicitBlockYield=null) {_implicitBlockYield()}'
end
it "should allow yield arguments" do
to_js( 'def func(x); yield :sym; end' ).
must_include 'function func(x, _implicitBlockYield=null) {_implicitBlockYield("sym")}'
end
end
describe "block_given?" do
it "should check for presence of implicit block" do
to_js( 'def func(); yield if block_given?; end' ).
must_include 'function func(_implicitBlockYield=null) {if (_implicitBlockYield) {_implicitBlockYield()}}'
end
end
end