opal 0.3.41 → 0.3.42

Sign up to get free protection for your applications and to get access to all the features.
Files changed (285) hide show
  1. data/.gitignore +2 -0
  2. data/.travis.yml +3 -0
  3. data/CHANGELOG.md +14 -1
  4. data/Gemfile +2 -5
  5. data/Rakefile +41 -3
  6. data/bin/opal +33 -0
  7. data/lib/opal.rb +2 -12
  8. data/lib/opal/core_ext.rb +5 -0
  9. data/lib/opal/grammar.rb +2207 -2138
  10. data/lib/opal/grammar.y +21 -0
  11. data/lib/opal/grammar_helpers.rb +360 -0
  12. data/lib/opal/lexer.rb +55 -401
  13. data/lib/opal/lexer_scope.rb +28 -0
  14. data/lib/opal/parser.rb +155 -171
  15. data/lib/opal/target_scope.rb +257 -0
  16. data/lib/opal/version.rb +1 -1
  17. data/opal.gemspec +6 -2
  18. data/opal/opal-parser.js.erb +3 -2
  19. data/opal/opal.rb +20 -18
  20. data/opal/opal/array.rb +21 -12
  21. data/opal/opal/basic_object.rb +2 -1
  22. data/opal/opal/boolean.rb +3 -0
  23. data/opal/opal/browser_loader.js +57 -0
  24. data/opal/opal/class.rb +51 -13
  25. data/opal/opal/date.rb +1 -20
  26. data/opal/opal/enumerable.rb +66 -33
  27. data/opal/opal/error.rb +2 -0
  28. data/opal/opal/hash.rb +1 -1
  29. data/opal/opal/kernel.rb +14 -3
  30. data/opal/opal/nil_class.rb +4 -0
  31. data/opal/opal/proc.rb +9 -1
  32. data/opal/opal/racc.rb +2 -2
  33. data/opal/opal/regexp.rb +1 -1
  34. data/opal/opal/runtime.js +14 -4
  35. data/opal/opal/string.rb +21 -4
  36. data/opal/opal/time.rb +27 -0
  37. data/spec/core/array/allocate_spec.rb +7 -1
  38. data/spec/core/array/append_spec.rb +18 -3
  39. data/spec/core/array/array_spec.rb +7 -0
  40. data/spec/core/array/assoc_spec.rb +23 -8
  41. data/spec/core/array/at_spec.rb +23 -3
  42. data/spec/core/array/choice_spec.rb +20 -0
  43. data/spec/core/array/clear_spec.rb +45 -4
  44. data/spec/core/array/combination_spec.rb +55 -0
  45. data/spec/core/array/compact_spec.rb +72 -1
  46. data/spec/core/array/constructor_spec.rb +13 -2
  47. data/spec/core/array/count_spec.rb +15 -7
  48. data/spec/core/array/delete_at_spec.rb +44 -1
  49. data/spec/core/array/delete_if_spec.rb +52 -2
  50. data/spec/core/array/delete_spec.rb +83 -2
  51. data/spec/core/array/drop_spec.rb +24 -16
  52. data/spec/core/array/drop_while_spec.rb +17 -0
  53. data/spec/core/array/each_index_spec.rb +11 -1
  54. data/spec/core/array/each_spec.rb +20 -2
  55. data/spec/core/array/empty_spec.rb +4 -1
  56. data/spec/core/array/eql_spec.rb +14 -0
  57. data/spec/core/array/fetch_spec.rb +31 -2
  58. data/spec/core/array/find_index_spec.rb +8 -0
  59. data/spec/core/array/first_spec.rb +45 -8
  60. data/spec/core/array/fixtures/classes.rb +538 -0
  61. data/spec/core/array/flatten_spec.rb +200 -7
  62. data/spec/core/array/frozen_spec.rb +32 -0
  63. data/spec/core/array/include_spec.rb +16 -1
  64. data/spec/core/array/index_spec.rb +5 -25
  65. data/spec/core/array/insert_spec.rb +37 -3
  66. data/spec/core/array/inspect_spec.rb +6 -12
  67. data/spec/core/array/intersection_spec.rb +55 -4
  68. data/spec/core/array/join_spec.rb +29 -4
  69. data/spec/core/array/keep_if_spec.rb +13 -6
  70. data/spec/core/array/last_spec.rb +35 -1
  71. data/spec/core/array/length_spec.rb +7 -4
  72. data/spec/core/array/map_spec.rb +9 -47
  73. data/spec/core/array/minus_spec.rb +68 -4
  74. data/spec/core/array/multiply_spec.rb +138 -6
  75. data/spec/core/array/new_spec.rb +92 -3
  76. data/spec/core/array/ntimes_spec.rb +26 -0
  77. data/spec/core/array/plus_spec.rb +48 -2
  78. data/spec/core/array/pop_spec.rb +159 -39
  79. data/spec/core/array/push_spec.rb +29 -1
  80. data/spec/core/array/rassoc_spec.rb +31 -2
  81. data/spec/core/array/reject_spec.rb +89 -2
  82. data/spec/core/array/replace_spec.rb +7 -29
  83. data/spec/core/array/reverse_each_spec.rb +25 -1
  84. data/spec/core/array/reverse_spec.rb +53 -1
  85. data/spec/core/array/rindex_spec.rb +55 -5
  86. data/spec/core/array/select_spec.rb +35 -8
  87. data/spec/core/array/shared/collect.rb +0 -0
  88. data/spec/core/array/shared/enumeratorize.rb +12 -0
  89. data/spec/core/array/shared/eql.rb +95 -0
  90. data/spec/core/array/shared/index.rb +37 -0
  91. data/spec/core/array/shared/inspect.rb +3 -0
  92. data/spec/core/array/shared/join.rb +7 -0
  93. data/spec/core/array/shared/keep_if.rb +0 -0
  94. data/spec/core/array/shared/length.rb +0 -0
  95. data/spec/core/array/shared/replace.rb +0 -0
  96. data/spec/core/array/shared/slice.rb +0 -0
  97. data/spec/core/array/shift_spec.rb +132 -23
  98. data/spec/core/array/shuffle_spec.rb +82 -6
  99. data/spec/core/array/size_spec.rb +7 -4
  100. data/spec/core/array/slice_spec.rb +132 -1
  101. data/spec/core/array/sort_spec.rb +263 -14
  102. data/spec/core/array/take_spec.rb +24 -16
  103. data/spec/core/array/take_while_spec.rb +14 -10
  104. data/spec/core/array/to_a_spec.rb +18 -1
  105. data/spec/core/array/to_ary_spec.rb +15 -1
  106. data/spec/core/array/try_convert_spec.rb +39 -2
  107. data/spec/core/array/uniq_spec.rb +148 -3
  108. data/spec/core/array/unshift_spec.rb +36 -1
  109. data/spec/core/array/zip_spec.rb +36 -1
  110. data/spec/core/class/new_spec.rb +8 -6
  111. data/spec/core/enumerable/all_spec.rb +37 -9
  112. data/spec/core/enumerable/any_spec.rb +45 -7
  113. data/spec/core/enumerable/collect_spec.rb +4 -1
  114. data/spec/core/enumerable/count_spec.rb +4 -1
  115. data/spec/core/enumerable/detect_spec.rb +2 -2
  116. data/spec/core/enumerable/drop_spec.rb +4 -1
  117. data/spec/core/enumerable/drop_while_spec.rb +4 -1
  118. data/spec/core/enumerable/each_slice_spec.rb +2 -1
  119. data/spec/core/enumerable/each_with_index_spec.rb +4 -1
  120. data/spec/core/enumerable/each_with_object_spec.rb +4 -1
  121. data/spec/core/enumerable/entries_spec.rb +4 -1
  122. data/spec/core/enumerable/find_all_spec.rb +4 -1
  123. data/spec/core/enumerable/find_index_spec.rb +4 -1
  124. data/spec/core/enumerable/find_spec.rb +5 -2
  125. data/spec/core/enumerable/first_spec.rb +4 -1
  126. data/spec/core/enumerable/fixtures/classes.rb +198 -2
  127. data/spec/core/enumerable/grep_spec.rb +4 -1
  128. data/spec/core/enumerable/take_spec.rb +4 -1
  129. data/spec/core/enumerable/to_a_spec.rb +4 -1
  130. data/spec/core/false/and_spec.rb +11 -0
  131. data/spec/core/false/inspect_spec.rb +7 -0
  132. data/spec/core/false/or_spec.rb +11 -0
  133. data/spec/core/false/to_s_spec.rb +7 -0
  134. data/spec/core/false/xor_spec.rb +11 -0
  135. data/spec/core/kernel/rand_spec.rb +5 -5
  136. data/spec/core/module/const_get_spec.rb +4 -4
  137. data/spec/core/module/fixtures/classes.rb +434 -0
  138. data/spec/core/module/method_defined_spec.rb +49 -0
  139. data/spec/core/module/module_function_spec.rb +28 -0
  140. data/spec/core/nil/and_spec.rb +3 -1
  141. data/spec/core/nil/dup_spec.rb +7 -0
  142. data/spec/core/nil/inspect_spec.rb +3 -1
  143. data/spec/core/nil/nil_spec.rb +3 -1
  144. data/spec/core/nil/or_spec.rb +4 -2
  145. data/spec/core/nil/to_a_spec.rb +3 -1
  146. data/spec/core/nil/to_f_spec.rb +3 -1
  147. data/spec/core/nil/to_i_spec.rb +3 -1
  148. data/spec/core/nil/to_s_spec.rb +3 -1
  149. data/spec/core/nil/xor_spec.rb +4 -2
  150. data/spec/core/string/element_reference_spec.rb +14 -1
  151. data/spec/core/string/fixtures/classes.rb +0 -0
  152. data/spec/core/true/and_spec.rb +11 -0
  153. data/spec/core/true/inspect_spec.rb +7 -0
  154. data/spec/core/true/or_spec.rb +11 -0
  155. data/spec/core/true/to_s_spec.rb +7 -0
  156. data/spec/core/true/xor_spec.rb +11 -0
  157. data/spec/{core → core_ext}/array/element_reference_spec.rb +0 -0
  158. data/spec/{core → core_ext}/array/equal_value_spec.rb +0 -0
  159. data/spec/{core → core_ext}/array/fill_spec.rb +0 -0
  160. data/spec/{core → core_ext}/array/reduce_spec.rb +0 -0
  161. data/spec/core_ext/basic_object/send_spec.rb +3 -3
  162. data/spec/{core → core_ext}/boolean/singleton_class_spec.rb +0 -0
  163. data/spec/{core → core_ext}/boolean/to_json_spec.rb +0 -0
  164. data/spec/core_ext/class/_inherited_spec.rb +3 -3
  165. data/spec/core_ext/class/proc_methods_spec.rb +2 -2
  166. data/spec/core_ext/class/singleton_methods_spec.rb +8 -8
  167. data/spec/core_ext/method_missing_spec.rb +3 -3
  168. data/spec/core_ext/native/method_missing_spec.rb +3 -2
  169. data/spec/core_ext/native/to_native_spec.rb +3 -2
  170. data/spec/{core → core_ext}/nil/to_json_spec.rb +0 -0
  171. data/spec/date.rb +0 -0
  172. data/spec/fileutils.rb +0 -0
  173. data/spec/filters/ancestors.rb +4 -0
  174. data/spec/filters/array_delete.rb +3 -0
  175. data/spec/filters/array_fetch.rb +3 -0
  176. data/spec/filters/array_first.rb +3 -0
  177. data/spec/filters/array_flatten.rb +14 -0
  178. data/spec/filters/array_intersection.rb +5 -0
  179. data/spec/filters/array_join.rb +6 -0
  180. data/spec/filters/array_subclasses.rb +4 -0
  181. data/spec/filters/block_args.rb +3 -0
  182. data/spec/filters/coerce_integer.rb +9 -0
  183. data/spec/filters/frozen.rb +4 -0
  184. data/spec/filters/mocks.rb +3 -0
  185. data/spec/filters/should_receive.rb +4 -0
  186. data/spec/filters/tainted.rb +7 -0
  187. data/spec/fixtures/class.rb +124 -0
  188. data/spec/fixtures/class_variables.rb +0 -0
  189. data/spec/fixtures/constants.rb +0 -0
  190. data/spec/grammar/alias_spec.rb +1 -1
  191. data/spec/grammar/def_spec.rb +1 -0
  192. data/spec/grammar/lvar_spec.rb +1 -2
  193. data/spec/grammar/nth_ref_spec.rb +13 -0
  194. data/spec/grammar/sclass_spec.rb +6 -7
  195. data/spec/grammar/str_spec.rb +4 -4
  196. data/spec/grammar/string_spec.rb +8 -0
  197. data/spec/grammar/xstr_spec.rb +4 -4
  198. data/spec/iconv.rb +0 -0
  199. data/spec/language/alias_spec.rb +140 -3
  200. data/spec/language/and_spec.rb +14 -7
  201. data/spec/language/array_spec.rb +57 -5
  202. data/spec/language/block_spec.rb +466 -49
  203. data/spec/language/break_spec.rb +294 -44
  204. data/spec/language/case_spec.rb +151 -3
  205. data/spec/language/class_spec.rb +196 -0
  206. data/spec/language/class_variable_spec.rb +56 -0
  207. data/spec/language/def_spec.rb +507 -4
  208. data/spec/language/defined_spec.rb +19 -7
  209. data/spec/language/ensure_spec.rb +26 -39
  210. data/spec/language/execution_spec.rb +15 -0
  211. data/spec/language/fixtures/array.rb +11 -0
  212. data/spec/language/fixtures/block.rb +57 -0
  213. data/spec/language/fixtures/break.rb +240 -0
  214. data/spec/language/fixtures/ensure.rb +72 -0
  215. data/spec/language/fixtures/literal_lambda.rb +7 -0
  216. data/spec/language/fixtures/metaclass.rb +33 -0
  217. data/spec/language/fixtures/module.rb +24 -0
  218. data/spec/language/fixtures/next.rb +78 -12
  219. data/spec/language/fixtures/return.rb +118 -0
  220. data/spec/language/fixtures/send.rb +110 -0
  221. data/spec/language/fixtures/send_1.9.rb +22 -0
  222. data/spec/language/fixtures/super.rb +308 -0
  223. data/spec/language/fixtures/variables.rb +58 -0
  224. data/spec/language/fixtures/yield.rb +5 -0
  225. data/spec/language/for_spec.rb +192 -0
  226. data/spec/language/hash_spec.rb +29 -5
  227. data/spec/language/if_spec.rb +90 -9
  228. data/spec/language/literal_lambda_spec.rb +1 -47
  229. data/spec/language/loop_spec.rb +39 -2
  230. data/spec/language/metaclass_spec.rb +151 -5
  231. data/spec/language/module_spec.rb +56 -0
  232. data/spec/language/next_spec.rb +370 -12
  233. data/spec/language/not_spec.rb +55 -0
  234. data/spec/language/numbers_spec.rb +56 -0
  235. data/spec/language/or_spec.rb +31 -3
  236. data/spec/language/order_spec.rb +79 -0
  237. data/spec/language/precedence_spec.rb +483 -0
  238. data/spec/language/proc_spec.rb +249 -21
  239. data/spec/language/redo_spec.rb +67 -0
  240. data/spec/language/rescue_spec.rb +121 -0
  241. data/spec/language/retry_spec.rb +56 -0
  242. data/spec/language/return_spec.rb +281 -0
  243. data/spec/language/send_spec.rb +141 -48
  244. data/spec/language/singleton_class_spec.rb +1 -1
  245. data/spec/language/string_spec.rb +11 -0
  246. data/spec/language/super_spec.rb +213 -133
  247. data/spec/language/symbol_spec.rb +2 -1
  248. data/spec/language/undef_spec.rb +3 -1
  249. data/spec/language/unless_spec.rb +6 -2
  250. data/spec/language/until_spec.rb +102 -3
  251. data/spec/language/variables_spec.rb +1212 -16
  252. data/spec/language/versions/array_1.9.rb +39 -0
  253. data/spec/language/versions/case_1.9.rb +20 -0
  254. data/spec/language/versions/hash_1.9.rb +18 -0
  255. data/spec/language/versions/literal_lambda_1.9.rb +143 -0
  256. data/spec/language/versions/not_1.9.rb +22 -0
  257. data/spec/language/versions/send_1.9.rb +241 -0
  258. data/spec/language/versions/symbol_1.9.rb +15 -0
  259. data/spec/language/versions/variables_1.9.rb +8 -0
  260. data/spec/language/while_spec.rb +70 -5
  261. data/spec/language/yield_spec.rb +32 -6
  262. data/spec/mspec/guards/block_device.rb +0 -0
  263. data/spec/mspec/guards/endian.rb +0 -0
  264. data/spec/mspec/helpers/environment.rb +0 -0
  265. data/spec/mspec/helpers/language_version.rb +0 -0
  266. data/spec/mspec/helpers/tmp.rb +0 -0
  267. data/spec/ospec/filter.rb +32 -0
  268. data/spec/ospec/main.rb.erb +18 -0
  269. data/spec/ospec/phantom.rb +97 -0
  270. data/spec/ospec/runner.rb +95 -0
  271. data/spec/ospec/sprockets.js +40 -0
  272. data/spec/pp.rb +3 -0
  273. data/spec/rbconfig.rb +5 -0
  274. data/spec/spec_helper.rb +53 -26
  275. data/spec/yaml.rb +0 -0
  276. metadata +275 -31
  277. data/config.ru +0 -8
  278. data/lib/opal/processor.rb +0 -47
  279. data/lib/opal/scope.rb +0 -236
  280. data/lib/opal/server.rb +0 -94
  281. data/spec/core/boolean/and_spec.rb +0 -17
  282. data/spec/core/boolean/inspect_spec.rb +0 -9
  283. data/spec/core/boolean/or_spec.rb +0 -17
  284. data/spec/core/boolean/to_s_spec.rb +0 -9
  285. data/spec/core/boolean/xor_spec.rb +0 -17
@@ -0,0 +1,15 @@
1
+ describe "A Symbol literal" do
2
+ pending "can be an empty string" do
3
+ c = :''
4
+ c.should be_kind_of(Symbol)
5
+ c.inspect.should == ':""'
6
+ end
7
+
8
+ # These weren't allowed on 1.8
9
+ pending "can be :!, :!=, or :!~" do
10
+ %w{'!', '!=', '!~'}.each do |sym|
11
+ lambda { sym.to_sym }.should_not raise_error(SyntaxError)
12
+ sym.to_sym.to_s.should == sym
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,8 @@
1
+ describe "Multiple assignments with splats" do
2
+ pending "* on the LHS has to be applied to any parameter" do
3
+ # a, *b, c = 1, 2, 3
4
+ a.should == 1
5
+ b.should == [2]
6
+ c.should == 3
7
+ end
8
+ end
@@ -1,3 +1,14 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ # while bool-expr [do]
4
+ # body
5
+ # end
6
+ #
7
+ # begin
8
+ # body
9
+ # end while bool-expr
10
+ #
11
+ # expr while bool-expr
1
12
  describe "The while expression" do
2
13
  it "runs while the expression is true" do
3
14
  i = 0
@@ -34,7 +45,7 @@ describe "The while expression" do
34
45
  a.should == 123
35
46
  end
36
47
 
37
- it "exectues code in containing variable scope with 'do'" do
48
+ it "executes code in containing variable scope with 'do'" do
38
49
  i = 0
39
50
  while i != 1 do
40
51
  a = 123
@@ -44,7 +55,7 @@ describe "The while expression" do
44
55
  a.should == 123
45
56
  end
46
57
 
47
- it "returns nil is ended when condition became false" do
58
+ it "returns nil if ended when condition became false" do
48
59
  i = 0
49
60
  while i < 3
50
61
  i += 1
@@ -94,7 +105,7 @@ describe "The while expression" do
94
105
  a = []
95
106
  i = 0
96
107
  j = 0
97
- while (i+=1) <3
108
+ while (i+=1)<3
98
109
  a << i
99
110
  j+=1
100
111
  redo if j<3
@@ -141,6 +152,20 @@ describe "The while modifier" do
141
152
  it "returns nil if interrupted by break with no arguments" do
142
153
  (break while true).should == nil
143
154
  end
155
+
156
+ it "skips to end of body with next" do
157
+ i = 0
158
+ j = 0
159
+ ((i+=1) == 3 ? next : j+=i) while i <= 10
160
+ j.should == 63
161
+ end
162
+
163
+ it "restarts the current iteration without reevaluating condition with redo" do
164
+ i = 0
165
+ j = 0
166
+ (i+=1) == 4 ? redo : j+=i while (i+=1) <= 10
167
+ j.should == 34
168
+ end
144
169
  end
145
170
 
146
171
  describe "The while modifier with begin .. end block" do
@@ -163,11 +188,51 @@ describe "The while modifier with begin .. end block" do
163
188
  i.should == 6
164
189
  end
165
190
 
166
- it "returns values passed to break if interrupted by break" do
191
+ it "returns value passed to break if interrupted by break" do
167
192
  (begin; break 123; end while true).should == 123
168
193
  end
169
194
 
170
195
  it "returns nil if interrupted by break with no arguments" do
171
196
  (begin; break; end while true).should == nil
172
197
  end
173
- end
198
+
199
+ pending "runs block at least once (even if the expression is false)" do
200
+ i = 0
201
+ begin
202
+ i += 1
203
+ end while false
204
+
205
+ i.should == 1
206
+ end
207
+
208
+ pending "evaluates condition after block execution" do
209
+ a = []
210
+ i = 0
211
+ begin
212
+ a << i
213
+ end while (i+=1)<5
214
+ a.should == [0, 1, 2, 3, 4]
215
+ end
216
+
217
+ pending "skips to end of body with next" do
218
+ a = []
219
+ i = 0
220
+ begin
221
+ next if i==3
222
+ a << i
223
+ end while (i+=1)<5
224
+ a.should == [0, 1, 2, 4]
225
+ end
226
+
227
+ pending "restarts the current iteration without reevaluting condition with redo" do
228
+ a = []
229
+ i = 0
230
+ j = 0
231
+ begin
232
+ a << i
233
+ j+=1
234
+ redo if j<3
235
+ end while (i+=1)<3
236
+ a.should == [0, 0, 0, 1, 2]
237
+ end
238
+ end
@@ -1,5 +1,11 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
1
2
  require File.expand_path('../fixtures/yield', __FILE__)
2
3
 
4
+ # Note that these specs use blocks defined as { |*a| ... } to capture the
5
+ # arguments with which the block is invoked. This is slightly confusing
6
+ # because the outer Array is a consequence of |*a| but it is necessary to
7
+ # clearly distinguish some behaviors.
8
+
3
9
  describe "The yield call" do
4
10
  before :each do
5
11
  @y = YieldSpecs::Yielder.new
@@ -9,6 +15,10 @@ describe "The yield call" do
9
15
  it "raises a LocalJumpError when the method is not passed a block" do
10
16
  lambda { @y.z }.should raise_error(LocalJumpError)
11
17
  end
18
+
19
+ pending "ignores assignment to the explicit block argument and calls the passed block" do
20
+ @y.ze { 42 }.should == 42
21
+ end
12
22
  end
13
23
 
14
24
  describe "taking a single argument" do
@@ -52,7 +62,7 @@ describe "The yield call" do
52
62
  @y.r(1) { |*a| a }.should == [1]
53
63
  end
54
64
 
55
- it "passes no arguments when the argument is an empty array" do
65
+ it "passes no arguments when the argument is an empty Array" do
56
66
  @y.r([]) { |*a| a }.should == []
57
67
  end
58
68
 
@@ -70,8 +80,16 @@ describe "The yield call" do
70
80
  @y.r([[]]) { |*a| a }.should == [[]]
71
81
  end
72
82
 
73
- it "passes nil as a value" do
74
- @y.r(nil) { |*a| a }.should == [nil]
83
+ ruby_version_is ""..."1.9" do
84
+ it "passes nil as a value" do
85
+ @y.r(nil) { |*a| a }.should == [nil]
86
+ end
87
+ end
88
+
89
+ ruby_version_is "1.9" do
90
+ pending "passes no values when give nil as an argument" do
91
+ @y.r(nil) { |*a| a }.should == []
92
+ end
75
93
  end
76
94
  end
77
95
 
@@ -95,8 +113,16 @@ describe "The yield call" do
95
113
  @y.rs(1, 2, [3, 4, 5]) { |*a| a }.should == [1, 2, 3, 4, 5]
96
114
  end
97
115
 
98
- it "passes nil as the argument value if the splatted argument is nil" do
99
- @y.rs(1, 2, nil) { |*a| a }.should == [1, 2, nil]
116
+ ruby_version_is ""..."1.9" do
117
+ it "passes nil as the argument value if the splatted argument is nil" do
118
+ @y.rs(1, 2, nil) { |*a| a }.should == [1, 2, nil]
119
+ end
120
+ end
121
+
122
+ ruby_version_is "1.9" do
123
+ pending "does not pass an argument value if the splatted argument is nil" do
124
+ @y.rs(1, 2, nil) { |*a| a }.should == [1, 2]
125
+ end
100
126
  end
101
127
  end
102
- end
128
+ end
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,32 @@
1
+ class OSpecFilter
2
+ def self.main
3
+ @main ||= self.new
4
+ end
5
+
6
+ def initialize
7
+ @filters = {}
8
+ end
9
+
10
+ def register
11
+ MSpec.register :exclude, self
12
+ end
13
+
14
+ def ===(description)
15
+ @filters.has_key? description
16
+ end
17
+
18
+ def register_filters(description, block)
19
+ instance_eval(&block)
20
+ end
21
+
22
+ def fails(description)
23
+ @filters[description] = true
24
+ end
25
+ end
26
+
27
+ class Object
28
+ def opal_filter(description, &block)
29
+ OSpecFilter.main.register_filters(description, block)
30
+ end
31
+ end
32
+
@@ -0,0 +1,18 @@
1
+ <% require_asset 'opal' %>
2
+ <% require_asset 'opal-parser' %>
3
+ <% require_asset 'mspec' %>
4
+ <% require_asset 'ospec/runner' %>
5
+
6
+ # Load all opal filters
7
+ <% Dir.glob('spec/filters/*.rb').each do |s| %>
8
+ <% require_asset s.sub(/^spec\//, '').sub(/\.rb$/, '') %>
9
+ <% end %>
10
+
11
+ # This file just greps for all spec files in spec/ and requires them
12
+ <% Dir.glob('spec/**/*_spec.{rb,opal}').each do |s| %>
13
+ <% require_asset s.sub(/^spec\//, '').sub(/\.(rb|opal)$/, '') %>
14
+ <% end %>
15
+
16
+ # All specs have been run, so we notify mspec that we are done
17
+ OSpecRunner.main.did_finish
18
+
@@ -0,0 +1,97 @@
1
+ class PhantomFormatter
2
+ def initialize(out=nil)
3
+ @exception = @failure = false
4
+ @exceptions = []
5
+ @count = 0
6
+ @examples = 0
7
+
8
+ @current_state = nil
9
+ end
10
+
11
+ def register
12
+ MSpec.register :exception, self
13
+ MSpec.register :before, self
14
+ MSpec.register :after, self
15
+ MSpec.register :start, self
16
+ MSpec.register :finish, self
17
+ MSpec.register :abort, self
18
+ MSpec.register :enter, self
19
+ end
20
+
21
+ def green(str)
22
+ `console.log('\\033[32m' + str + '\\033[0m')`
23
+ end
24
+
25
+ def red(str)
26
+ `console.log('\\033[31m' + str + '\\033[0m')`
27
+ end
28
+
29
+ def log(str)
30
+ `console.log(str)`
31
+ end
32
+
33
+ def exception?
34
+ @exception
35
+ end
36
+
37
+ def failure?
38
+ @failure
39
+ end
40
+
41
+ def enter(describe); end
42
+
43
+ def before(state=nil)
44
+ @current_state = nil
45
+ @failure = @exception = false
46
+ end
47
+
48
+ def exception(exception)
49
+ @count += 1
50
+ @failure = @exception ? @failure && exception.failure? : exception.failure?
51
+ @exception = true
52
+ @exceptions << exception
53
+ end
54
+
55
+ def after(state = nil)
56
+ @current_state = nil
57
+ @examples += 1
58
+ end
59
+
60
+ def start
61
+ @start_time = Time.now.to_f
62
+ end
63
+
64
+ def finish
65
+ time = Time.now.to_f - @start_time
66
+
67
+ if @exceptions.empty?
68
+ log "\nFinished"
69
+ green "#{@examples} examples, #{@count} failures (time taken: #{time})"
70
+
71
+ finish_with_code 0
72
+ else
73
+ log "\nFailures:"
74
+
75
+ @exceptions.each_with_index do |exception, idx|
76
+ log "\n #{idx + 1}. #{exception.description}"
77
+ red "\n #{exception.message}"
78
+ end
79
+
80
+ log "\nFinished"
81
+ red "#{@examples} examples, #{@count} failures (time taken: #{time})"
82
+
83
+ finish_with_code(1)
84
+ end
85
+ end
86
+
87
+ def finish_with_code(code)
88
+ %x{
89
+ if (typeof(phantom) !== 'undefined') {
90
+ return phantom.exit(code);
91
+ }
92
+ else {
93
+ window.OPAL_SPEC_CODE = code;
94
+ }
95
+ }
96
+ end
97
+ end
@@ -0,0 +1,95 @@
1
+ require 'ospec/phantom'
2
+ require 'ospec/filter'
3
+
4
+ # stdlib
5
+ require 'opal/date'
6
+ require 'opal/enumerator'
7
+
8
+ ENV = {}
9
+
10
+ class File
11
+ def self.expand_path(*a); nil; end
12
+ end
13
+
14
+ class ExceptionState
15
+ def initialize(state, location, exception)
16
+ @exception = exception
17
+
18
+ @description = location ? ["An exception occurred during: #{location}"] : []
19
+ if state
20
+ @description << "\n" unless @description.empty?
21
+ @description << state.description
22
+ @describe = state.describe
23
+ @it = state.it
24
+ @description = @description.join ""
25
+ else
26
+ @describe = @it = ""
27
+ end
28
+ end
29
+ end
30
+
31
+ module Kernel
32
+ def opal_eval(str)
33
+ code = Opal::Parser.new.parse str
34
+ `eval(#{code})`
35
+ end
36
+
37
+ def opal_parse(str, file='(string)')
38
+ Opal::Grammar.new.parse str, file
39
+ end
40
+
41
+ def opal_eval_compiled(javascript)
42
+ `eval(javascript)`
43
+ end
44
+
45
+ def eval(str)
46
+ opal_eval str
47
+ end
48
+ end
49
+
50
+ module Kernel
51
+ # FIXME: remove
52
+ def ruby_version_is(*); end
53
+ def pending(*); end
54
+ end
55
+
56
+ module MSpec
57
+ def self.opal_runner
58
+ @env = Object.new
59
+ @env.extend MSpec
60
+ end
61
+ end
62
+
63
+ class OSpecRunner
64
+ def self.main
65
+ @main ||= self.new
66
+ end
67
+
68
+ def initialize
69
+ register
70
+ run
71
+ end
72
+
73
+ def register
74
+ formatter = PhantomFormatter.new
75
+ formatter.register
76
+
77
+ OSpecFilter.main.register
78
+ end
79
+
80
+ def run
81
+ MSpec.opal_runner
82
+ end
83
+
84
+ def will_start
85
+ MSpec.actions :start
86
+ end
87
+
88
+ def did_finish
89
+ MSpec.actions :finish
90
+ end
91
+ end
92
+
93
+ # As soon as this file loads, tell the runner the specs are starting
94
+ OSpecRunner.main.will_start
95
+