opal 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (303) hide show
  1. data/.rspec +3 -0
  2. data/.travis.yml +0 -4
  3. data/README.md +6 -0
  4. data/Rakefile +30 -6
  5. data/bin/opal +6 -82
  6. data/corelib/{opal/array.rb → array.rb} +40 -56
  7. data/corelib/{opal/basic_object.rb → basic_object.rb} +2 -2
  8. data/corelib/{opal/boolean.rb → boolean.rb} +0 -8
  9. data/corelib/class.rb +47 -0
  10. data/corelib/{opal/comparable.rb → comparable.rb} +0 -0
  11. data/corelib/{opal/enumerable.rb → enumerable.rb} +208 -141
  12. data/corelib/{opal/enumerator.rb → enumerator.rb} +3 -3
  13. data/corelib/{opal/error.rb → error.rb} +1 -0
  14. data/corelib/{opal/hash.rb → hash.rb} +67 -56
  15. data/corelib/io.rb +39 -0
  16. data/corelib/{opal/kernel.rb → kernel.rb} +35 -31
  17. data/corelib/{opal/class.rb → module.rb} +29 -57
  18. data/corelib/native.rb +148 -0
  19. data/corelib/{opal/nil_class.rb → nil_class.rb} +2 -10
  20. data/corelib/{opal/numeric.rb → numeric.rb} +39 -14
  21. data/corelib/opal.rb +42 -25
  22. data/corelib/{opal/proc.rb → proc.rb} +3 -3
  23. data/corelib/{opal/range.rb → range.rb} +5 -1
  24. data/corelib/{opal/regexp.rb → regexp.rb} +0 -0
  25. data/corelib/{opal/runtime.js → runtime.js} +96 -188
  26. data/corelib/{opal/string.rb → string.rb} +20 -15
  27. data/corelib/struct.rb +139 -0
  28. data/corelib/{opal/time.rb → time.rb} +0 -0
  29. data/lib/opal.rb +4 -0
  30. data/lib/opal/cli.rb +79 -32
  31. data/lib/opal/cli_options.rb +91 -0
  32. data/lib/opal/erb.rb +41 -8
  33. data/lib/opal/grammar.rb +24 -10
  34. data/lib/opal/grammar.y +15 -4
  35. data/lib/opal/grammar_helpers.rb +4 -0
  36. data/lib/opal/lexer.rb +214 -143
  37. data/lib/opal/parser.rb +596 -562
  38. data/lib/opal/require_parser.rb +1 -1
  39. data/lib/opal/source_map.rb +15 -30
  40. data/lib/opal/target_scope.rb +24 -5
  41. data/lib/opal/version.rb +1 -1
  42. data/mri_spec/cli_spec.rb +18 -0
  43. data/mri_spec/fixtures/opal_file.rb +2 -0
  44. data/mri_spec/spec_helper.rb +17 -0
  45. data/opal.gemspec +5 -2
  46. data/spec/{rubyspec/filters → filters}/bugs/alias.rb +0 -0
  47. data/spec/{rubyspec/filters → filters}/bugs/ancestors.rb +0 -0
  48. data/spec/{rubyspec/filters → filters}/bugs/array.rb +0 -0
  49. data/spec/filters/bugs/array/combination.rb +11 -0
  50. data/spec/filters/bugs/array/count.rb +3 -0
  51. data/spec/filters/bugs/array/delete_if.rb +3 -0
  52. data/spec/filters/bugs/array/drop.rb +3 -0
  53. data/spec/filters/bugs/array/drop_while.rb +5 -0
  54. data/spec/filters/bugs/array/eql.rb +3 -0
  55. data/spec/filters/bugs/array/flatten.rb +9 -0
  56. data/spec/filters/bugs/array/minus.rb +5 -0
  57. data/spec/filters/bugs/array/multipliy.rb +9 -0
  58. data/spec/filters/bugs/array/new.rb +3 -0
  59. data/spec/filters/bugs/array/pop.rb +6 -0
  60. data/spec/filters/bugs/array/rassoc.rb +4 -0
  61. data/spec/filters/bugs/array/rindex.rb +6 -0
  62. data/spec/filters/bugs/array/select.rb +3 -0
  63. data/spec/filters/bugs/array/shift.rb +7 -0
  64. data/spec/filters/bugs/array/shuffle.rb +11 -0
  65. data/spec/filters/bugs/array/slice.rb +7 -0
  66. data/spec/filters/bugs/array/take.rb +3 -0
  67. data/spec/filters/bugs/array/to_a.rb +3 -0
  68. data/spec/filters/bugs/array/try_convert.rb +7 -0
  69. data/spec/filters/bugs/array/uniq.rb +10 -0
  70. data/spec/filters/bugs/array/zip.rb +4 -0
  71. data/spec/{rubyspec/filters → filters}/bugs/array_delete.rb +1 -0
  72. data/spec/{rubyspec/filters → filters}/bugs/array_fetch.rb +0 -0
  73. data/spec/{rubyspec/filters → filters}/bugs/array_first.rb +0 -0
  74. data/spec/{rubyspec/filters → filters}/bugs/array_flatten.rb +0 -0
  75. data/spec/{rubyspec/filters → filters}/bugs/array_intersection.rb +0 -0
  76. data/spec/{rubyspec/filters → filters}/bugs/array_join.rb +0 -0
  77. data/spec/{rubyspec/filters → filters}/bugs/break.rb +0 -0
  78. data/spec/filters/bugs/case.rb +4 -0
  79. data/spec/{rubyspec/filters → filters}/bugs/coerce_integer.rb +0 -0
  80. data/spec/filters/bugs/enumerable_sort_by.rb +3 -0
  81. data/spec/{rubyspec/filters → filters}/bugs/kernel/instance_variables.rb +0 -0
  82. data/spec/filters/bugs/kernel/rand.rb +4 -0
  83. data/spec/filters/bugs/language/array.rb +3 -0
  84. data/spec/filters/bugs/language/block.rb +6 -0
  85. data/spec/filters/bugs/language/break.rb +3 -0
  86. data/spec/{rubyspec/filters → filters}/bugs/language/class.rb +3 -0
  87. data/spec/{rubyspec/filters → filters}/bugs/language/class_variables.rb +0 -0
  88. data/spec/filters/bugs/language/def.rb +27 -0
  89. data/spec/filters/bugs/language/defined.rb +3 -0
  90. data/spec/filters/bugs/language/ensure.rb +4 -0
  91. data/spec/filters/bugs/language/execution.rb +4 -0
  92. data/spec/filters/bugs/language/for.rb +18 -0
  93. data/spec/filters/bugs/language/if.rb +13 -0
  94. data/spec/filters/bugs/language/loop.rb +4 -0
  95. data/spec/filters/bugs/language/metaclass.rb +14 -0
  96. data/spec/filters/bugs/language/module.rb +6 -0
  97. data/spec/filters/bugs/language/next.rb +3 -0
  98. data/spec/filters/bugs/language/or.rb +3 -0
  99. data/spec/filters/bugs/language/order.rb +4 -0
  100. data/spec/filters/bugs/language/precedence.rb +10 -0
  101. data/spec/filters/bugs/language/proc.rb +24 -0
  102. data/spec/filters/bugs/language/redo.rb +5 -0
  103. data/spec/filters/bugs/language/rescue.rb +9 -0
  104. data/spec/filters/bugs/language/retry.rb +5 -0
  105. data/spec/filters/bugs/language/send.rb +10 -0
  106. data/spec/filters/bugs/language/super.rb +9 -0
  107. data/spec/filters/bugs/language/until.rb +8 -0
  108. data/spec/filters/bugs/language/variables.rb +37 -0
  109. data/spec/filters/bugs/language/while.rb +6 -0
  110. data/spec/filters/bugs/language/yield.rb +5 -0
  111. data/spec/{rubyspec/filters → filters}/bugs/module/class_variables.rb +0 -0
  112. data/spec/filters/bugs/module/method_defined.rb +6 -0
  113. data/spec/filters/bugs/parser.rb +10 -0
  114. data/spec/{rubyspec/filters → filters}/bugs/public_methods.rb +1 -0
  115. data/spec/filters/bugs/return.rb +7 -0
  116. data/spec/filters/bugs/singleton/instance.rb +4 -0
  117. data/spec/filters/bugs/source_map.rb +3 -0
  118. data/spec/filters/bugs/string/center.rb +4 -0
  119. data/spec/filters/bugs/string/lines.rb +3 -0
  120. data/spec/{rubyspec/filters → filters}/mspec/mocks.rb +0 -0
  121. data/spec/{rubyspec/filters → filters}/mspec/ruby_exe.rb +0 -0
  122. data/spec/{rubyspec/filters → filters}/mspec/should_receive.rb +0 -0
  123. data/spec/{rubyspec/filters → filters}/parser/block_args.rb +0 -0
  124. data/spec/{rubyspec/filters → filters}/unsupported/array_subclasses.rb +1 -0
  125. data/spec/filters/unsupported/frozen.rb +32 -0
  126. data/spec/filters/unsupported/immutable_strings.rb +3 -0
  127. data/spec/filters/unsupported/tainted.rb +17 -0
  128. data/spec/filters/unsupported/trusted.rb +15 -0
  129. data/spec/opal/class/constants_spec.rb +7 -0
  130. data/spec/opal/erb/erb_spec.rb +7 -1
  131. data/spec/opal/erb/inline_block.opalerb +3 -0
  132. data/spec/opal/hash/allocate_spec.rb +16 -0
  133. data/spec/opal/hash/new_spec.rb +10 -0
  134. data/spec/opal/hash/to_s_spec.rb +9 -0
  135. data/spec/opal/kernel/instance_variable_defined_spec.rb +15 -0
  136. data/spec/opal/kernel/rand_spec.rb +5 -5
  137. data/spec/opal/kernel/respond_to_spec.rb +14 -1
  138. data/spec/opal/language/block_spec.rb +13 -0
  139. data/spec/opal/language/rescue_spec.rb +27 -0
  140. data/spec/opal/language/return_spec.rb +38 -0
  141. data/spec/opal/language/singleton_class_spec.rb +13 -0
  142. data/spec/opal/language/super_spec.rb +99 -0
  143. data/spec/opal/language/variables_spec.rb +20 -0
  144. data/spec/opal/module/attr_accessor_spec.rb +8 -0
  145. data/spec/opal/module/constants_spec.rb +2 -2
  146. data/spec/opal/native/alias_native_spec.rb +18 -0
  147. data/spec/opal/native/each_spec.rb +14 -0
  148. data/spec/opal/native/element_reference_spec.rb +14 -0
  149. data/spec/opal/native/method_missing_spec.rb +39 -0
  150. data/spec/opal/native/new_spec.rb +19 -0
  151. data/spec/opal/native/nil_spec.rb +14 -0
  152. data/spec/opal/runtime2/class_hierarchy_spec.rb +2 -2
  153. data/spec/opal/source_map_spec.rb +3 -7
  154. data/spec/ospec/main.rb.erb +2 -5
  155. data/spec/parser/alias_spec.rb +4 -4
  156. data/spec/parser/and_spec.rb +2 -2
  157. data/spec/parser/array_spec.rb +6 -6
  158. data/spec/parser/attrasgn_spec.rb +8 -8
  159. data/spec/parser/begin_spec.rb +11 -11
  160. data/spec/parser/block_spec.rb +3 -3
  161. data/spec/parser/break_spec.rb +4 -4
  162. data/spec/parser/call_spec.rb +50 -48
  163. data/spec/parser/class_spec.rb +2 -2
  164. data/spec/parser/const_spec.rb +1 -1
  165. data/spec/parser/cvar_spec.rb +1 -1
  166. data/spec/parser/def_spec.rb +5 -5
  167. data/spec/parser/gvar_spec.rb +2 -2
  168. data/spec/parser/hash_spec.rb +4 -4
  169. data/spec/parser/iasgn_spec.rb +3 -3
  170. data/spec/parser/if_spec.rb +6 -6
  171. data/spec/parser/iter_spec.rb +6 -6
  172. data/spec/parser/lambda_spec.rb +5 -5
  173. data/spec/parser/lasgn_spec.rb +2 -2
  174. data/spec/parser/line_spec.rb +2 -2
  175. data/spec/parser/lvar_spec.rb +5 -5
  176. data/spec/parser/masgn_spec.rb +1 -1
  177. data/spec/parser/module_spec.rb +2 -2
  178. data/spec/parser/not_spec.rb +4 -4
  179. data/spec/parser/op_asgn1_spec.rb +2 -2
  180. data/spec/parser/op_asgn2_spec.rb +2 -2
  181. data/spec/parser/or_spec.rb +2 -2
  182. data/spec/parser/parse_spec.rb +66 -0
  183. data/spec/parser/parser_spec.rb +32 -38
  184. data/spec/parser/regexp_spec.rb +4 -4
  185. data/spec/parser/return_spec.rb +4 -4
  186. data/spec/parser/sclass_spec.rb +4 -4
  187. data/spec/parser/str_spec.rb +3 -3
  188. data/spec/parser/super_spec.rb +6 -6
  189. data/spec/parser/undef_spec.rb +3 -3
  190. data/spec/parser/unless_spec.rb +4 -4
  191. data/spec/parser/while_spec.rb +3 -3
  192. data/spec/parser/xstr_spec.rb +3 -3
  193. data/spec/parser/yield_spec.rb +6 -6
  194. data/spec/rubyspec/core/array/drop_spec.rb +1 -1
  195. data/spec/rubyspec/core/array/keep_if_spec.rb +1 -3
  196. data/spec/rubyspec/core/array/length_spec.rb +1 -3
  197. data/spec/rubyspec/core/array/map_spec.rb +2 -6
  198. data/spec/rubyspec/core/array/minus_spec.rb +3 -3
  199. data/spec/rubyspec/core/array/multiply_spec.rb +14 -16
  200. data/spec/rubyspec/core/array/new_spec.rb +3 -5
  201. data/spec/rubyspec/core/array/plus_spec.rb +2 -2
  202. data/spec/rubyspec/core/array/pop_spec.rb +4 -4
  203. data/spec/rubyspec/core/array/rassoc_spec.rb +2 -2
  204. data/spec/rubyspec/core/array/reject_spec.rb +2 -6
  205. data/spec/rubyspec/core/array/replace_spec.rb +1 -3
  206. data/spec/rubyspec/core/array/reverse_each_spec.rb +1 -3
  207. data/spec/rubyspec/core/array/reverse_spec.rb +4 -4
  208. data/spec/rubyspec/core/array/rindex_spec.rb +1 -1
  209. data/spec/rubyspec/core/array/select_spec.rb +3 -7
  210. data/spec/rubyspec/core/array/shared/collect.rb +7 -0
  211. data/spec/rubyspec/core/array/shared/index.rb +1 -1
  212. data/spec/rubyspec/core/array/shared/keep_if.rb +3 -0
  213. data/spec/rubyspec/core/array/shared/length.rb +3 -0
  214. data/spec/rubyspec/core/array/shared/replace.rb +3 -0
  215. data/spec/rubyspec/core/array/shared/slice.rb +3 -0
  216. data/spec/rubyspec/core/array/shuffle_spec.rb +1 -1
  217. data/spec/rubyspec/core/array/size_spec.rb +1 -3
  218. data/spec/rubyspec/core/array/slice_spec.rb +4 -6
  219. data/spec/rubyspec/core/array/sort_spec.rb +2 -2
  220. data/spec/rubyspec/core/array/to_a_spec.rb +1 -1
  221. data/spec/rubyspec/core/array/try_convert_spec.rb +7 -7
  222. data/spec/rubyspec/core/array/uniq_spec.rb +7 -7
  223. data/spec/rubyspec/core/array/zip_spec.rb +1 -1
  224. data/spec/rubyspec/core/enumerable/collect_spec.rb +24 -0
  225. data/spec/rubyspec/core/enumerable/count_spec.rb +35 -19
  226. data/spec/rubyspec/core/enumerable/find_spec.rb +5 -0
  227. data/spec/rubyspec/core/hash/each_pair_spec.rb +7 -7
  228. data/spec/rubyspec/core/hash/each_spec.rb +13 -7
  229. data/spec/rubyspec/core/module/method_defined_spec.rb +4 -4
  230. data/spec/rubyspec/core/module/public_method_defined_spec.rb +19 -0
  231. data/spec/rubyspec/core/module/remove_const_spec.rb +23 -0
  232. data/spec/rubyspec/core/numeric/step_spec.rb +14 -0
  233. data/spec/rubyspec/core/string/center_spec.rb +43 -65
  234. data/spec/rubyspec/core/string/lines_spec.rb +1 -1
  235. data/spec/rubyspec/core/string/ljust_spec.rb +25 -9
  236. data/spec/rubyspec/core/string/rjust_spec.rb +26 -10
  237. data/spec/rubyspec/core/struct/fixtures/classes.rb +26 -0
  238. data/spec/rubyspec/core/struct/initialize_spec.rb +11 -0
  239. data/spec/rubyspec/core/struct/new_spec.rb +24 -0
  240. data/spec/rubyspec/fixtures/constants.rb +7 -0
  241. data/spec/rubyspec/language/break_spec.rb +1 -1
  242. data/spec/rubyspec/language/case_spec.rb +30 -30
  243. data/spec/rubyspec/language/def_spec.rb +34 -34
  244. data/spec/rubyspec/language/defined_spec.rb +2 -2
  245. data/spec/rubyspec/language/ensure_spec.rb +2 -2
  246. data/spec/rubyspec/language/execution_spec.rb +2 -2
  247. data/spec/rubyspec/language/for_spec.rb +17 -17
  248. data/spec/rubyspec/language/hash_spec.rb +3 -3
  249. data/spec/rubyspec/language/if_spec.rb +11 -11
  250. data/spec/rubyspec/language/loop_spec.rb +3 -3
  251. data/spec/rubyspec/language/metaclass_spec.rb +14 -14
  252. data/spec/rubyspec/language/module_spec.rb +6 -6
  253. data/spec/rubyspec/language/next_spec.rb +5 -5
  254. data/spec/rubyspec/language/not_spec.rb +1 -1
  255. data/spec/rubyspec/language/or_spec.rb +1 -1
  256. data/spec/rubyspec/language/order_spec.rb +3 -5
  257. data/spec/rubyspec/language/precedence_spec.rb +19 -19
  258. data/spec/rubyspec/language/proc_spec.rb +29 -29
  259. data/spec/rubyspec/language/redo_spec.rb +3 -5
  260. data/spec/rubyspec/language/rescue_spec.rb +7 -7
  261. data/spec/rubyspec/language/retry_spec.rb +2 -2
  262. data/spec/rubyspec/language/return_spec.rb +12 -12
  263. data/spec/rubyspec/language/send_spec.rb +9 -9
  264. data/spec/rubyspec/language/singleton_class_spec.rb +3 -4
  265. data/spec/rubyspec/language/super_spec.rb +7 -11
  266. data/spec/rubyspec/language/until_spec.rb +10 -10
  267. data/spec/rubyspec/language/variables_spec.rb +59 -67
  268. data/spec/rubyspec/language/versions/array_1.9.rb +1 -1
  269. data/spec/rubyspec/language/versions/block_1.9.rb +0 -0
  270. data/spec/rubyspec/language/versions/break_1.9.rb +0 -0
  271. data/spec/rubyspec/language/versions/literal_lambda_1.9.rb +12 -12
  272. data/spec/rubyspec/language/versions/send_1.9.rb +23 -23
  273. data/spec/rubyspec/language/versions/symbol_1.9.rb +2 -2
  274. data/spec/rubyspec/language/versions/variables_1.9.rb +1 -1
  275. data/spec/rubyspec/language/while_spec.rb +4 -4
  276. data/spec/rubyspec/language/yield_spec.rb +3 -3
  277. data/spec/rubyspec/library/erb/util/html_escape_spec.rb +10 -0
  278. data/spec/rubyspec/library/singleton/clone_spec.rb +8 -0
  279. data/spec/rubyspec/library/singleton/dup_spec.rb +8 -0
  280. data/spec/rubyspec/library/singleton/fixtures/classes.rb +18 -0
  281. data/spec/rubyspec/library/singleton/instance_spec.rb +30 -0
  282. data/spec/spec_helper.rb +214 -0
  283. data/stdlib/buffer.rb +40 -0
  284. data/stdlib/buffer/array.rb +66 -0
  285. data/stdlib/buffer/view.rb +70 -0
  286. data/stdlib/erb.rb +11 -20
  287. data/stdlib/forwardable.rb +71 -0
  288. data/stdlib/json.rb +78 -0
  289. data/stdlib/ostruct.rb +69 -0
  290. data/stdlib/rbconfig.rb +1 -0
  291. data/stdlib/singleton.rb +40 -0
  292. data/stdlib/stringio.rb +173 -0
  293. data/stdlib/template.rb +44 -0
  294. metadata +285 -79
  295. data/corelib/opal/native.rb +0 -31
  296. data/spec/opal/class/bridge_class_spec.rb +0 -39
  297. data/spec/opal/native_spec.rb +0 -209
  298. data/spec/ospec/runner.rb +0 -223
  299. data/spec/rubyspec/filters/bugs/block_args.rb +0 -3
  300. data/spec/rubyspec/filters/bugs/case.rb +0 -8
  301. data/spec/rubyspec/filters/bugs/language/module.rb +0 -3
  302. data/spec/rubyspec/filters/unsupported/frozen.rb +0 -4
  303. data/spec/rubyspec/filters/unsupported/tainted.rb +0 -7
@@ -1,29 +1,45 @@
1
1
  require File.expand_path('../../../spec_helper', __FILE__)
2
2
  require File.expand_path('../fixtures/classes', __FILE__)
3
3
 
4
- describe "Enumerable#count" do
5
- before :each do
6
- @elements = [1, 2, 4, 2]
7
- @numerous = EnumerableSpecs::Numerous.new(*@elements)
8
- end
4
+ ruby_version_is "1.8.7" do
5
+ describe "Enumerable#count" do
6
+ before :each do
7
+ @elements = [1, 2, 4, 2]
8
+ @numerous = EnumerableSpecs::Numerous.new(*@elements)
9
+ end
9
10
 
10
- it "returns size when no argument or a block" do
11
- @numerous.count.should == 4
12
- end
11
+ it "returns size when no argument or a block" do
12
+ @numerous.count.should == 4
13
+ end
13
14
 
14
- it "counts nils if given nil as an argument" do
15
- EnumerableSpecs::Numerous.new(nil, nil, nil, false).count(nil).should == 3
16
- end
15
+ it "counts nils if given nil as an argument" do
16
+ EnumerableSpecs::Numerous.new(nil, nil, nil, false).count(nil).should == 3
17
+ end
17
18
 
18
- it "accepts an argument for comparison using ==" do
19
- @numerous.count(2).should == 2
20
- end
19
+ it "accepts an argument for comparison using ==" do
20
+ @numerous.count(2).should == 2
21
+ end
21
22
 
22
- it "uses a block for comparison" do
23
- @numerous.count{|x| x%2==0 }.should == 3
24
- end
23
+ it "uses a block for comparison" do
24
+ @numerous.count{|x| x%2==0 }.should == 3
25
+ end
26
+
27
+ it "ignores the block when given an argument" do
28
+ @numerous.count(4){|x| x%2==0 }.should == 1
29
+ end
30
+
31
+ ruby_version_is ""..."1.9" do
32
+ it "gathers whole arrays as elements when each yields multiple" do
33
+ multi = EnumerableSpecs::YieldsMulti.new
34
+ multi.count {|e| e == [1, 2]}.should == 1
35
+ end
36
+ end
25
37
 
26
- it "ignores the block when given an argument" do
27
- @numerous.count(4){|x| x%2==0 }.should == 1
38
+ ruby_version_is "1.9" do
39
+ it "gathers initial args as elements when each yields multiple" do
40
+ multi = EnumerableSpecs::YieldsMulti.new
41
+ multi.count {|e| e == 1 }.should == 1
42
+ end
43
+ end
28
44
  end
29
45
  end
@@ -48,4 +48,9 @@ describe "Enumerable#find" do
48
48
  fail_proc = lambda { "yay" }
49
49
  @empty.find(fail_proc) {|e| true}.should == "yay"
50
50
  end
51
+
52
+ it "gathers whole arrays as elements when each yields multiple" do
53
+ multi = EnumerableSpecs::YieldsMulti.new
54
+ multi.find {|e| e == [1, 2] }.should == [1, 2]
55
+ end
51
56
  end
@@ -7,12 +7,12 @@ describe "Hash#each_pair" do
7
7
  end
8
8
 
9
9
  # FIXME: should be: h.each { |k,| ary << k }
10
- it "yields the key only to a block expecting |key,|" do
11
- ary = []
12
- h = {"a" => 1, "b" => 2, "c" => 3}
13
- h.each_pair { |k| ary << k }
14
- ary.should == ["a", "b", "c"]
15
- end
10
+ #it "yields the key only to a block expecting |key,|" do
11
+ # ary = []
12
+ # h = {"a" => 1, "b" => 2, "c" => 3}
13
+ # h.each_pair { |k| ary << k }
14
+ # ary.should == ["a", "b", "c"]
15
+ #end
16
16
 
17
17
  it "uses the same order as keys() and values()" do
18
18
  h = {:a => 1, :b => 2, :c => 3, :d => 5}
@@ -27,4 +27,4 @@ describe "Hash#each_pair" do
27
27
  keys.should == h.keys
28
28
  values.should == h.values
29
29
  end
30
- end
30
+ end
@@ -1,4 +1,10 @@
1
1
  describe "Hash#each" do
2
+ it "yields a [[key, value]] Array for each pair to a block expecting |*args|" do
3
+ all_args = []
4
+ {1 => 2, 3 => 4}.each { |*args| all_args << args }
5
+ all_args.sort.should == [[[1, 2]], [[3, 4]]]
6
+ end
7
+
2
8
  it "yields the key and value of each pair to a block expecting |key, value|" do
3
9
  r = {}
4
10
  h = {:a => 1, :b => 2, :c => 3, :d => 5}
@@ -7,12 +13,12 @@ describe "Hash#each" do
7
13
  end
8
14
 
9
15
  # FIXME: should be: h.each { |k,| ary << k }
10
- it "yields the key only to a block expecting |key,|" do
11
- ary = []
12
- h = {"a" => 1, "b" => 2, "c" => 3}
13
- h.each { |k| ary << k }
14
- ary.should == ["a", "b", "c"]
15
- end
16
+ #it "yields the key only to a block expecting |key,|" do
17
+ # ary = []
18
+ # h = {"a" => 1, "b" => 2, "c" => 3}
19
+ # h.each { |k| ary << k }
20
+ # ary.should == ["a", "b", "c"]
21
+ #end
16
22
 
17
23
  it "uses the same order as keys() and values()" do
18
24
  h = {:a => 1, :b => 2, :c => 3, :d => 5}
@@ -27,4 +33,4 @@ describe "Hash#each" do
27
33
  keys.should == h.keys
28
34
  values.should == h.values
29
35
  end
30
- end
36
+ end
@@ -2,7 +2,7 @@ require File.expand_path('../../../spec_helper', __FILE__)
2
2
  require File.expand_path('../fixtures/classes', __FILE__)
3
3
 
4
4
  describe "Module#method_defined?" do
5
- pending "returns true if a public or private method with the given name is defined in self, self's ancestors or one of self's included modules" do
5
+ it "returns true if a public or private method with the given name is defined in self, self's ancestors or one of self's included modules" do
6
6
  # Defined in Child
7
7
  ModuleSpecs::Child.method_defined?(:public_child).should == true
8
8
  ModuleSpecs::Child.method_defined?("private_child").should == false
@@ -24,13 +24,13 @@ describe "Module#method_defined?" do
24
24
  end
25
25
 
26
26
  # unlike alias_method, module_function, public, and friends,
27
- pending "does not search Object or Kernel when called on a module" do
27
+ it "does not search Object or Kernel when called on a module" do
28
28
  m = Module.new
29
29
 
30
30
  m.method_defined?(:module_specs_public_method_on_kernel).should be_false
31
31
  end
32
32
 
33
- pending "raises a TypeError when the given object is not a string/symbol/fixnum" do
33
+ it "raises a TypeError when the given object is not a string/symbol/fixnum" do
34
34
  c = Class.new
35
35
  o = mock('123')
36
36
 
@@ -40,7 +40,7 @@ describe "Module#method_defined?" do
40
40
  lambda { c.method_defined?(o) }.should raise_error(TypeError)
41
41
  end
42
42
 
43
- pending "converts the given name to a string using to_str" do
43
+ it "converts the given name to a string using to_str" do
44
44
  c = Class.new { def test(); end }
45
45
  (o = mock('test')).should_receive(:to_str).and_return("test")
46
46
 
@@ -0,0 +1,19 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+ require File.expand_path('../fixtures/classes', __FILE__)
3
+
4
+ describe "Module#public_method_defined?" do
5
+ it "returns true if the named public method is defined by module or its ancestors" do
6
+ ModuleSpecs::CountsMixin.public_method_defined?("public_3").should == true
7
+
8
+ ModuleSpecs::CountsParent.public_method_defined?("public_3").should == true
9
+ ModuleSpecs::CountsParent.public_method_defined?("public_2").should == true
10
+
11
+ ModuleSpecs::CountsChild.public_method_defined?("public_3").should == true
12
+ ModuleSpecs::CountsChild.public_method_defined?("public_2").should == true
13
+ ModuleSpecs::CountsChild.public_method_defined?("public_1").should == true
14
+ end
15
+
16
+ it "returns false if the named method is not defined by the module or its ancestors" do
17
+ ModuleSpecs::CountsMixin.public_method_defined?(:public_10).should == false
18
+ end
19
+ end
@@ -0,0 +1,23 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+ require File.expand_path('../../../fixtures/constants', __FILE__)
3
+
4
+ describe "Module#remove_const" do
5
+ it "removes the constant specified by a String or Symbol from the receiver's constant table" do
6
+ ConstantSpecs::ModuleM::CS_CONST252 = :const252
7
+ ConstantSpecs::ModuleM::CS_CONST252.should == :const252
8
+
9
+ ConstantSpecs::ModuleM.send :remove_const, :CS_CONST252
10
+ lambda { ConstantSpecs::ModuleM::CS_CONST252 }.should raise_error(NameError)
11
+
12
+ ConstantSpecs::ModuleM::CS_CONST253 = :const253
13
+ ConstantSpecs::ModuleM::CS_CONST253.should == :const253
14
+
15
+ ConstantSpecs::ModuleM.send :remove_const, "CS_CONST253"
16
+ lambda { ConstantSpecs::ModuleM::CS_CONST253 }.should raise_error(NameError)
17
+ end
18
+
19
+ it "returns the value of the removed constant" do
20
+ ConstantSpecs::ModuleM::CS_CONST254 = :const254
21
+ ConstantSpecs::ModuleM.send(:remove_const, :CS_CONST254).should == :const254
22
+ end
23
+ end
@@ -0,0 +1,14 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+ #require File.expand_path('../fixtures/classes', __FILE__)
3
+
4
+ describe "Numeric#step" do
5
+ before :each do
6
+ ScratchPad.record []
7
+ @prc = lambda { |x| ScratchPad << x }
8
+ end
9
+
10
+ it "defaults to step = 1" do
11
+ 1.step(5, &@prc)
12
+ ScratchPad.recorded.should == [1, 2, 3, 4, 5]
13
+ end
14
+ end
@@ -1,71 +1,49 @@
1
- describe "String#center" do
2
-
3
- it "does nothing if the specified width is lower than the string's size" do
4
- "abc".center(2).should == "abc"
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../../../spec_helper', __FILE__)
3
+ require File.expand_path('../fixtures/classes.rb', __FILE__)
4
+
5
+ describe "String#center with length, padding" do
6
+ it "returns a new string of specified length with self centered and padded with padstr" do
7
+ "one".center(9, '.').should == "...one..."
8
+ "hello".center(20, '123').should == "1231231hello12312312"
9
+ "middle".center(13, '-').should == "---middle----"
10
+
11
+ "".center(1, "abcd").should == "a"
12
+ "".center(2, "abcd").should == "aa"
13
+ "".center(3, "abcd").should == "aab"
14
+ "".center(4, "abcd").should == "abab"
15
+ "".center(6, "xy").should == "xyxxyx"
16
+ "".center(11, "12345").should == "12345123451"
17
+
18
+ "|".center(2, "abcd").should == "|a"
19
+ "|".center(3, "abcd").should == "a|a"
20
+ "|".center(4, "abcd").should == "a|ab"
21
+ "|".center(5, "abcd").should == "ab|ab"
22
+ "|".center(6, "xy").should == "xy|xyx"
23
+ "|".center(7, "xy").should == "xyx|xyx"
24
+ "|".center(11, "12345").should == "12345|12345"
25
+ "|".center(12, "12345").should == "12345|123451"
26
+
27
+ "||".center(3, "abcd").should == "||a"
28
+ "||".center(4, "abcd").should == "a||a"
29
+ "||".center(5, "abcd").should == "a||ab"
30
+ "||".center(6, "abcd").should == "ab||ab"
31
+ "||".center(8, "xy").should == "xyx||xyx"
32
+ "||".center(12, "12345").should == "12345||12345"
33
+ "||".center(13, "12345").should == "12345||123451"
5
34
  end
6
35
 
7
- it "center a string with a strange pattern" do
8
- "ab".center(17, '12345').should == "1234512ab12345123"
36
+ it "pads with whitespace if no padstr is given" do
37
+ "two".center(5).should == " two "
38
+ "hello".center(20).should == " hello "
9
39
  end
10
40
 
11
- describe "centers an odd string with a odd number of padding strings" do
12
- it "uses default padding" do
13
- "abc".center(5).should == " abc "
14
- end
15
-
16
- it "uses a custum padding" do
17
- "abc".center(5, '-').should == "-abc-"
18
- end
19
-
20
- it "works with bigger patterns" do
21
- "abc".center(7, '~!{').should == "~!abc~!"
22
- end
23
-
24
- it "repeats the pattern if needed" do
25
- "abc".center(10, '~!{').should == "~!{abc~!{~"
26
- end
41
+ it "returns self if it's longer than or as long as the specified length" do
42
+ "".center(0).should == ""
43
+ "".center(-1).should == ""
44
+ "hello".center(4).should == "hello"
45
+ "hello".center(-1).should == "hello"
46
+ "this".center(3).should == "this"
47
+ "radiology".center(8, '-').should == "radiology"
27
48
  end
28
-
29
- describe "centers an even string with an odd number of padding strings" do
30
- it "uses default padding" do
31
- "abcd".center(7).should == " abcd "
32
- end
33
-
34
- it "works with bigger patterns" do
35
- "abcd".center(7, '~!{').should == "~abcd~!"
36
- end
37
-
38
- it "repeats the pattern if needed" do
39
- "abcd".center(11, '~!{').should == "~!{abcd~!{~"
40
- end
41
- end
42
-
43
- describe "centers an even string with an even number of padding strings" do
44
- it "uses default padding" do
45
- "abcd".center(8).should == " abcd "
46
- end
47
-
48
- it "works with bigger patterns" do
49
- "abcd".center(8, '~!{').should == "~!abcd~!"
50
- end
51
-
52
- it "repeats the pattern if needed" do
53
- "abcd".center(12, '~!{').should == "~!{~abcd~!{~"
54
- end
55
- end
56
-
57
- describe "center an odd string with an even number" do
58
- it "uses default padding" do
59
- "abc".center(4).should == "abc "
60
- end
61
-
62
- it "works with bigger patterns" do
63
- "abc".center(4, '~!{').should == "abc~"
64
- end
65
-
66
- it "repeats the pattern if needed" do
67
- "abc".center(12, '~!{').should == "~!{~abc~!{~!"
68
- end
69
- end
70
-
71
49
  end
@@ -1,5 +1,5 @@
1
1
  describe "String#lines" do
2
- pending "should split on the default record separator and return enumerator if not block is given" do
2
+ it "should split on the default record separator and return enumerator if not block is given" do
3
3
  "first\nsecond\nthird".lines.class.should == Enumerator
4
4
  "first\nsecond\nthird".lines.entries.class.should == Array
5
5
  "first\nsecond\nthird".lines.entries.size.should == 3
@@ -1,17 +1,33 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../../../spec_helper', __FILE__)
3
+ require File.expand_path('../fixtures/classes.rb', __FILE__)
4
+
1
5
  describe "String#ljust" do
2
- it "does nothing if the specified width is lower than the string's size" do
3
- "abc".ljust(2).should == "abc"
4
- end
6
+ it "returns a new string of specified length with self left justified and padded with padstr" do
7
+ "hello".ljust(20, '1234').should == "hello123412341234123"
8
+
9
+ "".ljust(1, "abcd").should == "a"
10
+ "".ljust(2, "abcd").should == "ab"
11
+ "".ljust(3, "abcd").should == "abc"
12
+ "".ljust(4, "abcd").should == "abcd"
13
+ "".ljust(6, "abcd").should == "abcdab"
5
14
 
6
- it "uses default padding" do
7
- "abc".ljust(5).should == " abc"
15
+ "OK".ljust(3, "abcd").should == "OKa"
16
+ "OK".ljust(4, "abcd").should == "OKab"
17
+ "OK".ljust(6, "abcd").should == "OKabcd"
18
+ "OK".ljust(8, "abcd").should == "OKabcdab"
8
19
  end
9
20
 
10
- it "uses a custum padding" do
11
- "abc".ljust(5, '-').should == "--abc"
21
+ it "pads with whitespace if no padstr is given" do
22
+ "hello".ljust(20).should == "hello "
12
23
  end
13
24
 
14
- it "uses wisely a bigger pattern" do
15
- "abc".ljust(10, "123").should == "1231231abc"
25
+ it "returns self if it's longer than or as long as the specified length" do
26
+ "".ljust(0).should == ""
27
+ "".ljust(-1).should == ""
28
+ "hello".ljust(4).should == "hello"
29
+ "hello".ljust(-1).should == "hello"
30
+ "this".ljust(3).should == "this"
31
+ "radiology".ljust(8, '-').should == "radiology"
16
32
  end
17
33
  end
@@ -1,17 +1,33 @@
1
- describe "String#rjust" do
2
- it "does nothing if the specified width is lower than the string's size" do
3
- "abc".rjust(2).should == "abc"
4
- end
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../../../spec_helper', __FILE__)
3
+ require File.expand_path('../fixtures/classes.rb', __FILE__)
4
+
5
+ describe "String#rjust with length, padding" do
6
+ it "returns a new string of specified length with self right justified and padded with padstr" do
7
+ "hello".rjust(20, '1234').should == "123412341234123hello"
8
+
9
+ "".rjust(1, "abcd").should == "a"
10
+ "".rjust(2, "abcd").should == "ab"
11
+ "".rjust(3, "abcd").should == "abc"
12
+ "".rjust(4, "abcd").should == "abcd"
13
+ "".rjust(6, "abcd").should == "abcdab"
5
14
 
6
- it "uses default padding" do
7
- "abc".rjust(5).should == "abc "
15
+ "OK".rjust(3, "abcd").should == "aOK"
16
+ "OK".rjust(4, "abcd").should == "abOK"
17
+ "OK".rjust(6, "abcd").should == "abcdOK"
18
+ "OK".rjust(8, "abcd").should == "abcdabOK"
8
19
  end
9
20
 
10
- it "uses a custum padding" do
11
- "abc".rjust(5, '-').should == "abc--"
21
+ it "pads with whitespace if no padstr is given" do
22
+ "hello".rjust(20).should == " hello"
12
23
  end
13
24
 
14
- it "uses wisely a bigger pattern" do
15
- "abc".rjust(10, "123").should == "abc1231231"
25
+ it "returns self if it's longer than or as long as the specified length" do
26
+ "".rjust(0).should == ""
27
+ "".rjust(-1).should == ""
28
+ "hello".rjust(4).should == "hello"
29
+ "hello".rjust(-1).should == "hello"
30
+ "this".rjust(3).should == "this"
31
+ "radiology".rjust(8, '-').should == "radiology"
16
32
  end
17
33
  end
@@ -0,0 +1,26 @@
1
+ module StructClasses
2
+
3
+ class Apple < Struct; end
4
+
5
+ Ruby = Struct.new(:version, :platform)
6
+
7
+ Car = Struct.new(:make, :model, :year)
8
+
9
+ class Honda < Car
10
+ def initialize(*args)
11
+ self.make = "Honda"
12
+ super(*args)
13
+ end
14
+ end
15
+
16
+ class SubclassX < Struct
17
+ end
18
+
19
+ class SubclassX
20
+ attr_reader :key
21
+ def initialize(*)
22
+ @key = :value
23
+ super
24
+ end
25
+ end
26
+ end