opal 0.4.3 → 0.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.rspec +3 -0
- data/.travis.yml +0 -4
- data/README.md +6 -0
- data/Rakefile +30 -6
- data/bin/opal +6 -82
- data/corelib/{opal/array.rb → array.rb} +40 -56
- data/corelib/{opal/basic_object.rb → basic_object.rb} +2 -2
- data/corelib/{opal/boolean.rb → boolean.rb} +0 -8
- data/corelib/class.rb +47 -0
- data/corelib/{opal/comparable.rb → comparable.rb} +0 -0
- data/corelib/{opal/enumerable.rb → enumerable.rb} +208 -141
- data/corelib/{opal/enumerator.rb → enumerator.rb} +3 -3
- data/corelib/{opal/error.rb → error.rb} +1 -0
- data/corelib/{opal/hash.rb → hash.rb} +67 -56
- data/corelib/io.rb +39 -0
- data/corelib/{opal/kernel.rb → kernel.rb} +35 -31
- data/corelib/{opal/class.rb → module.rb} +29 -57
- data/corelib/native.rb +148 -0
- data/corelib/{opal/nil_class.rb → nil_class.rb} +2 -10
- data/corelib/{opal/numeric.rb → numeric.rb} +39 -14
- data/corelib/opal.rb +42 -25
- data/corelib/{opal/proc.rb → proc.rb} +3 -3
- data/corelib/{opal/range.rb → range.rb} +5 -1
- data/corelib/{opal/regexp.rb → regexp.rb} +0 -0
- data/corelib/{opal/runtime.js → runtime.js} +96 -188
- data/corelib/{opal/string.rb → string.rb} +20 -15
- data/corelib/struct.rb +139 -0
- data/corelib/{opal/time.rb → time.rb} +0 -0
- data/lib/opal.rb +4 -0
- data/lib/opal/cli.rb +79 -32
- data/lib/opal/cli_options.rb +91 -0
- data/lib/opal/erb.rb +41 -8
- data/lib/opal/grammar.rb +24 -10
- data/lib/opal/grammar.y +15 -4
- data/lib/opal/grammar_helpers.rb +4 -0
- data/lib/opal/lexer.rb +214 -143
- data/lib/opal/parser.rb +596 -562
- data/lib/opal/require_parser.rb +1 -1
- data/lib/opal/source_map.rb +15 -30
- data/lib/opal/target_scope.rb +24 -5
- data/lib/opal/version.rb +1 -1
- data/mri_spec/cli_spec.rb +18 -0
- data/mri_spec/fixtures/opal_file.rb +2 -0
- data/mri_spec/spec_helper.rb +17 -0
- data/opal.gemspec +5 -2
- data/spec/{rubyspec/filters → filters}/bugs/alias.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/ancestors.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array.rb +0 -0
- data/spec/filters/bugs/array/combination.rb +11 -0
- data/spec/filters/bugs/array/count.rb +3 -0
- data/spec/filters/bugs/array/delete_if.rb +3 -0
- data/spec/filters/bugs/array/drop.rb +3 -0
- data/spec/filters/bugs/array/drop_while.rb +5 -0
- data/spec/filters/bugs/array/eql.rb +3 -0
- data/spec/filters/bugs/array/flatten.rb +9 -0
- data/spec/filters/bugs/array/minus.rb +5 -0
- data/spec/filters/bugs/array/multipliy.rb +9 -0
- data/spec/filters/bugs/array/new.rb +3 -0
- data/spec/filters/bugs/array/pop.rb +6 -0
- data/spec/filters/bugs/array/rassoc.rb +4 -0
- data/spec/filters/bugs/array/rindex.rb +6 -0
- data/spec/filters/bugs/array/select.rb +3 -0
- data/spec/filters/bugs/array/shift.rb +7 -0
- data/spec/filters/bugs/array/shuffle.rb +11 -0
- data/spec/filters/bugs/array/slice.rb +7 -0
- data/spec/filters/bugs/array/take.rb +3 -0
- data/spec/filters/bugs/array/to_a.rb +3 -0
- data/spec/filters/bugs/array/try_convert.rb +7 -0
- data/spec/filters/bugs/array/uniq.rb +10 -0
- data/spec/filters/bugs/array/zip.rb +4 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_delete.rb +1 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_fetch.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_first.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_flatten.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_intersection.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_join.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/break.rb +0 -0
- data/spec/filters/bugs/case.rb +4 -0
- data/spec/{rubyspec/filters → filters}/bugs/coerce_integer.rb +0 -0
- data/spec/filters/bugs/enumerable_sort_by.rb +3 -0
- data/spec/{rubyspec/filters → filters}/bugs/kernel/instance_variables.rb +0 -0
- data/spec/filters/bugs/kernel/rand.rb +4 -0
- data/spec/filters/bugs/language/array.rb +3 -0
- data/spec/filters/bugs/language/block.rb +6 -0
- data/spec/filters/bugs/language/break.rb +3 -0
- data/spec/{rubyspec/filters → filters}/bugs/language/class.rb +3 -0
- data/spec/{rubyspec/filters → filters}/bugs/language/class_variables.rb +0 -0
- data/spec/filters/bugs/language/def.rb +27 -0
- data/spec/filters/bugs/language/defined.rb +3 -0
- data/spec/filters/bugs/language/ensure.rb +4 -0
- data/spec/filters/bugs/language/execution.rb +4 -0
- data/spec/filters/bugs/language/for.rb +18 -0
- data/spec/filters/bugs/language/if.rb +13 -0
- data/spec/filters/bugs/language/loop.rb +4 -0
- data/spec/filters/bugs/language/metaclass.rb +14 -0
- data/spec/filters/bugs/language/module.rb +6 -0
- data/spec/filters/bugs/language/next.rb +3 -0
- data/spec/filters/bugs/language/or.rb +3 -0
- data/spec/filters/bugs/language/order.rb +4 -0
- data/spec/filters/bugs/language/precedence.rb +10 -0
- data/spec/filters/bugs/language/proc.rb +24 -0
- data/spec/filters/bugs/language/redo.rb +5 -0
- data/spec/filters/bugs/language/rescue.rb +9 -0
- data/spec/filters/bugs/language/retry.rb +5 -0
- data/spec/filters/bugs/language/send.rb +10 -0
- data/spec/filters/bugs/language/super.rb +9 -0
- data/spec/filters/bugs/language/until.rb +8 -0
- data/spec/filters/bugs/language/variables.rb +37 -0
- data/spec/filters/bugs/language/while.rb +6 -0
- data/spec/filters/bugs/language/yield.rb +5 -0
- data/spec/{rubyspec/filters → filters}/bugs/module/class_variables.rb +0 -0
- data/spec/filters/bugs/module/method_defined.rb +6 -0
- data/spec/filters/bugs/parser.rb +10 -0
- data/spec/{rubyspec/filters → filters}/bugs/public_methods.rb +1 -0
- data/spec/filters/bugs/return.rb +7 -0
- data/spec/filters/bugs/singleton/instance.rb +4 -0
- data/spec/filters/bugs/source_map.rb +3 -0
- data/spec/filters/bugs/string/center.rb +4 -0
- data/spec/filters/bugs/string/lines.rb +3 -0
- data/spec/{rubyspec/filters → filters}/mspec/mocks.rb +0 -0
- data/spec/{rubyspec/filters → filters}/mspec/ruby_exe.rb +0 -0
- data/spec/{rubyspec/filters → filters}/mspec/should_receive.rb +0 -0
- data/spec/{rubyspec/filters → filters}/parser/block_args.rb +0 -0
- data/spec/{rubyspec/filters → filters}/unsupported/array_subclasses.rb +1 -0
- data/spec/filters/unsupported/frozen.rb +32 -0
- data/spec/filters/unsupported/immutable_strings.rb +3 -0
- data/spec/filters/unsupported/tainted.rb +17 -0
- data/spec/filters/unsupported/trusted.rb +15 -0
- data/spec/opal/class/constants_spec.rb +7 -0
- data/spec/opal/erb/erb_spec.rb +7 -1
- data/spec/opal/erb/inline_block.opalerb +3 -0
- data/spec/opal/hash/allocate_spec.rb +16 -0
- data/spec/opal/hash/new_spec.rb +10 -0
- data/spec/opal/hash/to_s_spec.rb +9 -0
- data/spec/opal/kernel/instance_variable_defined_spec.rb +15 -0
- data/spec/opal/kernel/rand_spec.rb +5 -5
- data/spec/opal/kernel/respond_to_spec.rb +14 -1
- data/spec/opal/language/block_spec.rb +13 -0
- data/spec/opal/language/rescue_spec.rb +27 -0
- data/spec/opal/language/return_spec.rb +38 -0
- data/spec/opal/language/singleton_class_spec.rb +13 -0
- data/spec/opal/language/super_spec.rb +99 -0
- data/spec/opal/language/variables_spec.rb +20 -0
- data/spec/opal/module/attr_accessor_spec.rb +8 -0
- data/spec/opal/module/constants_spec.rb +2 -2
- data/spec/opal/native/alias_native_spec.rb +18 -0
- data/spec/opal/native/each_spec.rb +14 -0
- data/spec/opal/native/element_reference_spec.rb +14 -0
- data/spec/opal/native/method_missing_spec.rb +39 -0
- data/spec/opal/native/new_spec.rb +19 -0
- data/spec/opal/native/nil_spec.rb +14 -0
- data/spec/opal/runtime2/class_hierarchy_spec.rb +2 -2
- data/spec/opal/source_map_spec.rb +3 -7
- data/spec/ospec/main.rb.erb +2 -5
- data/spec/parser/alias_spec.rb +4 -4
- data/spec/parser/and_spec.rb +2 -2
- data/spec/parser/array_spec.rb +6 -6
- data/spec/parser/attrasgn_spec.rb +8 -8
- data/spec/parser/begin_spec.rb +11 -11
- data/spec/parser/block_spec.rb +3 -3
- data/spec/parser/break_spec.rb +4 -4
- data/spec/parser/call_spec.rb +50 -48
- data/spec/parser/class_spec.rb +2 -2
- data/spec/parser/const_spec.rb +1 -1
- data/spec/parser/cvar_spec.rb +1 -1
- data/spec/parser/def_spec.rb +5 -5
- data/spec/parser/gvar_spec.rb +2 -2
- data/spec/parser/hash_spec.rb +4 -4
- data/spec/parser/iasgn_spec.rb +3 -3
- data/spec/parser/if_spec.rb +6 -6
- data/spec/parser/iter_spec.rb +6 -6
- data/spec/parser/lambda_spec.rb +5 -5
- data/spec/parser/lasgn_spec.rb +2 -2
- data/spec/parser/line_spec.rb +2 -2
- data/spec/parser/lvar_spec.rb +5 -5
- data/spec/parser/masgn_spec.rb +1 -1
- data/spec/parser/module_spec.rb +2 -2
- data/spec/parser/not_spec.rb +4 -4
- data/spec/parser/op_asgn1_spec.rb +2 -2
- data/spec/parser/op_asgn2_spec.rb +2 -2
- data/spec/parser/or_spec.rb +2 -2
- data/spec/parser/parse_spec.rb +66 -0
- data/spec/parser/parser_spec.rb +32 -38
- data/spec/parser/regexp_spec.rb +4 -4
- data/spec/parser/return_spec.rb +4 -4
- data/spec/parser/sclass_spec.rb +4 -4
- data/spec/parser/str_spec.rb +3 -3
- data/spec/parser/super_spec.rb +6 -6
- data/spec/parser/undef_spec.rb +3 -3
- data/spec/parser/unless_spec.rb +4 -4
- data/spec/parser/while_spec.rb +3 -3
- data/spec/parser/xstr_spec.rb +3 -3
- data/spec/parser/yield_spec.rb +6 -6
- data/spec/rubyspec/core/array/drop_spec.rb +1 -1
- data/spec/rubyspec/core/array/keep_if_spec.rb +1 -3
- data/spec/rubyspec/core/array/length_spec.rb +1 -3
- data/spec/rubyspec/core/array/map_spec.rb +2 -6
- data/spec/rubyspec/core/array/minus_spec.rb +3 -3
- data/spec/rubyspec/core/array/multiply_spec.rb +14 -16
- data/spec/rubyspec/core/array/new_spec.rb +3 -5
- data/spec/rubyspec/core/array/plus_spec.rb +2 -2
- data/spec/rubyspec/core/array/pop_spec.rb +4 -4
- data/spec/rubyspec/core/array/rassoc_spec.rb +2 -2
- data/spec/rubyspec/core/array/reject_spec.rb +2 -6
- data/spec/rubyspec/core/array/replace_spec.rb +1 -3
- data/spec/rubyspec/core/array/reverse_each_spec.rb +1 -3
- data/spec/rubyspec/core/array/reverse_spec.rb +4 -4
- data/spec/rubyspec/core/array/rindex_spec.rb +1 -1
- data/spec/rubyspec/core/array/select_spec.rb +3 -7
- data/spec/rubyspec/core/array/shared/collect.rb +7 -0
- data/spec/rubyspec/core/array/shared/index.rb +1 -1
- data/spec/rubyspec/core/array/shared/keep_if.rb +3 -0
- data/spec/rubyspec/core/array/shared/length.rb +3 -0
- data/spec/rubyspec/core/array/shared/replace.rb +3 -0
- data/spec/rubyspec/core/array/shared/slice.rb +3 -0
- data/spec/rubyspec/core/array/shuffle_spec.rb +1 -1
- data/spec/rubyspec/core/array/size_spec.rb +1 -3
- data/spec/rubyspec/core/array/slice_spec.rb +4 -6
- data/spec/rubyspec/core/array/sort_spec.rb +2 -2
- data/spec/rubyspec/core/array/to_a_spec.rb +1 -1
- data/spec/rubyspec/core/array/try_convert_spec.rb +7 -7
- data/spec/rubyspec/core/array/uniq_spec.rb +7 -7
- data/spec/rubyspec/core/array/zip_spec.rb +1 -1
- data/spec/rubyspec/core/enumerable/collect_spec.rb +24 -0
- data/spec/rubyspec/core/enumerable/count_spec.rb +35 -19
- data/spec/rubyspec/core/enumerable/find_spec.rb +5 -0
- data/spec/rubyspec/core/hash/each_pair_spec.rb +7 -7
- data/spec/rubyspec/core/hash/each_spec.rb +13 -7
- data/spec/rubyspec/core/module/method_defined_spec.rb +4 -4
- data/spec/rubyspec/core/module/public_method_defined_spec.rb +19 -0
- data/spec/rubyspec/core/module/remove_const_spec.rb +23 -0
- data/spec/rubyspec/core/numeric/step_spec.rb +14 -0
- data/spec/rubyspec/core/string/center_spec.rb +43 -65
- data/spec/rubyspec/core/string/lines_spec.rb +1 -1
- data/spec/rubyspec/core/string/ljust_spec.rb +25 -9
- data/spec/rubyspec/core/string/rjust_spec.rb +26 -10
- data/spec/rubyspec/core/struct/fixtures/classes.rb +26 -0
- data/spec/rubyspec/core/struct/initialize_spec.rb +11 -0
- data/spec/rubyspec/core/struct/new_spec.rb +24 -0
- data/spec/rubyspec/fixtures/constants.rb +7 -0
- data/spec/rubyspec/language/break_spec.rb +1 -1
- data/spec/rubyspec/language/case_spec.rb +30 -30
- data/spec/rubyspec/language/def_spec.rb +34 -34
- data/spec/rubyspec/language/defined_spec.rb +2 -2
- data/spec/rubyspec/language/ensure_spec.rb +2 -2
- data/spec/rubyspec/language/execution_spec.rb +2 -2
- data/spec/rubyspec/language/for_spec.rb +17 -17
- data/spec/rubyspec/language/hash_spec.rb +3 -3
- data/spec/rubyspec/language/if_spec.rb +11 -11
- data/spec/rubyspec/language/loop_spec.rb +3 -3
- data/spec/rubyspec/language/metaclass_spec.rb +14 -14
- data/spec/rubyspec/language/module_spec.rb +6 -6
- data/spec/rubyspec/language/next_spec.rb +5 -5
- data/spec/rubyspec/language/not_spec.rb +1 -1
- data/spec/rubyspec/language/or_spec.rb +1 -1
- data/spec/rubyspec/language/order_spec.rb +3 -5
- data/spec/rubyspec/language/precedence_spec.rb +19 -19
- data/spec/rubyspec/language/proc_spec.rb +29 -29
- data/spec/rubyspec/language/redo_spec.rb +3 -5
- data/spec/rubyspec/language/rescue_spec.rb +7 -7
- data/spec/rubyspec/language/retry_spec.rb +2 -2
- data/spec/rubyspec/language/return_spec.rb +12 -12
- data/spec/rubyspec/language/send_spec.rb +9 -9
- data/spec/rubyspec/language/singleton_class_spec.rb +3 -4
- data/spec/rubyspec/language/super_spec.rb +7 -11
- data/spec/rubyspec/language/until_spec.rb +10 -10
- data/spec/rubyspec/language/variables_spec.rb +59 -67
- data/spec/rubyspec/language/versions/array_1.9.rb +1 -1
- data/spec/rubyspec/language/versions/block_1.9.rb +0 -0
- data/spec/rubyspec/language/versions/break_1.9.rb +0 -0
- data/spec/rubyspec/language/versions/literal_lambda_1.9.rb +12 -12
- data/spec/rubyspec/language/versions/send_1.9.rb +23 -23
- data/spec/rubyspec/language/versions/symbol_1.9.rb +2 -2
- data/spec/rubyspec/language/versions/variables_1.9.rb +1 -1
- data/spec/rubyspec/language/while_spec.rb +4 -4
- data/spec/rubyspec/language/yield_spec.rb +3 -3
- data/spec/rubyspec/library/erb/util/html_escape_spec.rb +10 -0
- data/spec/rubyspec/library/singleton/clone_spec.rb +8 -0
- data/spec/rubyspec/library/singleton/dup_spec.rb +8 -0
- data/spec/rubyspec/library/singleton/fixtures/classes.rb +18 -0
- data/spec/rubyspec/library/singleton/instance_spec.rb +30 -0
- data/spec/spec_helper.rb +214 -0
- data/stdlib/buffer.rb +40 -0
- data/stdlib/buffer/array.rb +66 -0
- data/stdlib/buffer/view.rb +70 -0
- data/stdlib/erb.rb +11 -20
- data/stdlib/forwardable.rb +71 -0
- data/stdlib/json.rb +78 -0
- data/stdlib/ostruct.rb +69 -0
- data/stdlib/rbconfig.rb +1 -0
- data/stdlib/singleton.rb +40 -0
- data/stdlib/stringio.rb +173 -0
- data/stdlib/template.rb +44 -0
- metadata +285 -79
- data/corelib/opal/native.rb +0 -31
- data/spec/opal/class/bridge_class_spec.rb +0 -39
- data/spec/opal/native_spec.rb +0 -209
- data/spec/ospec/runner.rb +0 -223
- data/spec/rubyspec/filters/bugs/block_args.rb +0 -3
- data/spec/rubyspec/filters/bugs/case.rb +0 -8
- data/spec/rubyspec/filters/bugs/language/module.rb +0 -3
- data/spec/rubyspec/filters/unsupported/frozen.rb +0 -4
- data/spec/rubyspec/filters/unsupported/tainted.rb +0 -7
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
require File.expand_path('../fixtures/classes', __FILE__)
|
3
|
+
|
4
|
+
describe "Struct#initialize" do
|
5
|
+
|
6
|
+
it "does nothing when passed a set of fields equal to self" do
|
7
|
+
car = same_car = StructClasses::Car.new("Honda", "Accord", "1998")
|
8
|
+
car.instance_eval { initialize("Honda", "Accord", "1998") }
|
9
|
+
car.should == same_car
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
require File.expand_path('../fixtures/classes', __FILE__)
|
3
|
+
|
4
|
+
describe "Struct.new" do
|
5
|
+
it "creates a constant in Struct namespace with string as first argument" do
|
6
|
+
struct = Struct.new('Animal', :name, :legs, :eyeballs)
|
7
|
+
struct.should == Struct::Animal
|
8
|
+
struct.name.should == "Struct::Animal"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "creates an instance" do
|
12
|
+
StructClasses::Ruby.new.kind_of?(StructClasses::Ruby).should == true
|
13
|
+
end
|
14
|
+
|
15
|
+
it "creates reader methods" do
|
16
|
+
StructClasses::Ruby.new.should have_method(:version)
|
17
|
+
StructClasses::Ruby.new.should have_method(:platform)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "creates writer methods" do
|
21
|
+
StructClasses::Ruby.new.should have_method(:version=)
|
22
|
+
StructClasses::Ruby.new.should have_method(:platform=)
|
23
|
+
end
|
24
|
+
end
|
@@ -245,44 +245,44 @@ end
|
|
245
245
|
|
246
246
|
describe "The 'case'-construct with no target expression" do
|
247
247
|
it "evaluates the body of the first clause when at least one of its condition expressions is true" do
|
248
|
-
|
249
|
-
|
250
|
-
|
248
|
+
case
|
249
|
+
when true, false; 'foo'
|
250
|
+
end.should == 'foo'
|
251
251
|
end
|
252
252
|
|
253
253
|
it "evaluates the body of the first when clause that is not false/nil" do
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
254
|
+
case
|
255
|
+
when false; 'foo'
|
256
|
+
when 2; 'bar'
|
257
|
+
when 1 == 1; 'baz'
|
258
|
+
end.should == 'bar'
|
259
|
+
|
260
|
+
case
|
261
|
+
when false; 'foo'
|
262
|
+
when nil; 'foo'
|
263
|
+
when 1 == 1; 'bar'
|
264
|
+
end.should == 'bar'
|
265
265
|
end
|
266
266
|
|
267
267
|
it "evaluates the body of the else clause if all when clauses are false/nil" do
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
268
|
+
case
|
269
|
+
when false; 'foo'
|
270
|
+
when nil; 'foo'
|
271
|
+
when 1 == 2; 'bar'
|
272
|
+
else 'baz'
|
273
|
+
end.should == 'baz'
|
274
274
|
end
|
275
275
|
|
276
276
|
it "evaluates multiple conditional expressions as a boolean disjunction" do
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
277
|
+
case
|
278
|
+
when true, false; 'foo'
|
279
|
+
else 'bar'
|
280
|
+
end.should == 'foo'
|
281
|
+
|
282
|
+
case
|
283
|
+
when false, true; 'foo'
|
284
|
+
else 'bar'
|
285
|
+
end.should == 'foo'
|
286
286
|
end
|
287
287
|
|
288
288
|
it "evaluates true as only 'true' when true is the first clause" do
|
@@ -307,4 +307,4 @@ describe "The 'case'-construct with no target expression" do
|
|
307
307
|
end
|
308
308
|
end
|
309
309
|
|
310
|
-
|
310
|
+
language_version __FILE__, "case"
|
@@ -12,7 +12,7 @@ describe "Redefining a method" do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
describe "Defining an 'initialize' method" do
|
15
|
-
|
15
|
+
it "sets the method's visibility to private" do
|
16
16
|
class DefInitializeSpec
|
17
17
|
def initialize
|
18
18
|
end
|
@@ -22,7 +22,7 @@ describe "Defining an 'initialize' method" do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
describe "Defining an 'initialize_copy' method" do
|
25
|
-
|
25
|
+
it "sets the method's visibility to private" do
|
26
26
|
class DefInitializeCopySpec
|
27
27
|
def initialize_copy
|
28
28
|
end
|
@@ -120,10 +120,10 @@ end
|
|
120
120
|
|
121
121
|
describe "A singleton method definition" do
|
122
122
|
after :all do
|
123
|
-
Object.remove_class_variable :@@a rescue nil
|
123
|
+
#Object.remove_class_variable :@@a rescue nil
|
124
124
|
end
|
125
125
|
|
126
|
-
|
126
|
+
it "can be declared for a local variable" do
|
127
127
|
a = "hi"
|
128
128
|
def a.foo
|
129
129
|
5
|
@@ -131,7 +131,7 @@ describe "A singleton method definition" do
|
|
131
131
|
a.foo.should == 5
|
132
132
|
end
|
133
133
|
|
134
|
-
|
134
|
+
it "can be declared for an instance variable" do
|
135
135
|
@a = "hi"
|
136
136
|
def @a.foo
|
137
137
|
6
|
@@ -139,7 +139,7 @@ describe "A singleton method definition" do
|
|
139
139
|
@a.foo.should == 6
|
140
140
|
end
|
141
141
|
|
142
|
-
|
142
|
+
it "can be declared for a global variable" do
|
143
143
|
$__a__ = "hi"
|
144
144
|
def $__a__.foo
|
145
145
|
7
|
@@ -147,7 +147,7 @@ describe "A singleton method definition" do
|
|
147
147
|
$__a__.foo.should == 7
|
148
148
|
end
|
149
149
|
|
150
|
-
|
150
|
+
it "can be declared for a class variable" do
|
151
151
|
@@a = "hi"
|
152
152
|
def @@a.foo
|
153
153
|
8
|
@@ -155,14 +155,14 @@ describe "A singleton method definition" do
|
|
155
155
|
@@a.foo.should == 8
|
156
156
|
end
|
157
157
|
|
158
|
-
|
158
|
+
it "can be declared with an empty method body" do
|
159
159
|
class DefSpec
|
160
160
|
def self.foo;end
|
161
161
|
end
|
162
162
|
DefSpec.foo.should == nil
|
163
163
|
end
|
164
164
|
|
165
|
-
|
165
|
+
it "can be redefined" do
|
166
166
|
obj = Object.new
|
167
167
|
def obj.==(other)
|
168
168
|
1
|
@@ -183,7 +183,7 @@ describe "A singleton method definition" do
|
|
183
183
|
end
|
184
184
|
|
185
185
|
ruby_version_is "1.9" do
|
186
|
-
|
186
|
+
it "raises RuntimeError if frozen" do
|
187
187
|
obj = Object.new
|
188
188
|
obj.freeze
|
189
189
|
lambda { def obj.foo; end }.should raise_error(RuntimeError)
|
@@ -192,7 +192,7 @@ describe "A singleton method definition" do
|
|
192
192
|
end
|
193
193
|
|
194
194
|
describe "Redefining a singleton method" do
|
195
|
-
|
195
|
+
it "does not inherit a previously set visibility " do
|
196
196
|
o = Object.new
|
197
197
|
|
198
198
|
class << o; private; def foo; end; end;
|
@@ -205,10 +205,10 @@ describe "Redefining a singleton method" do
|
|
205
205
|
class << o; should have_instance_method(:foo); end
|
206
206
|
|
207
207
|
end
|
208
|
-
end
|
208
|
+
end if false
|
209
209
|
|
210
210
|
describe "Redefining a singleton method" do
|
211
|
-
|
211
|
+
it "does not inherit a previously set visibility " do
|
212
212
|
o = Object.new
|
213
213
|
|
214
214
|
class << o; private; def foo; end; end;
|
@@ -221,10 +221,10 @@ describe "Redefining a singleton method" do
|
|
221
221
|
class << o; should have_instance_method(:foo); end
|
222
222
|
|
223
223
|
end
|
224
|
-
end
|
224
|
+
end if false
|
225
225
|
|
226
226
|
describe "A method defined with extreme default arguments" do
|
227
|
-
|
227
|
+
it "can redefine itself when the default is evaluated" do
|
228
228
|
class DefSpecs
|
229
229
|
def foo(x = (def foo; "hello"; end;1));x;end
|
230
230
|
end
|
@@ -235,7 +235,7 @@ describe "A method defined with extreme default arguments" do
|
|
235
235
|
d.foo.should == 'hello'
|
236
236
|
end
|
237
237
|
|
238
|
-
|
238
|
+
it "may use an fcall as a default" do
|
239
239
|
def foo(x = caller())
|
240
240
|
x
|
241
241
|
end
|
@@ -264,7 +264,7 @@ describe "A method defined with extreme default arguments" do
|
|
264
264
|
end
|
265
265
|
|
266
266
|
describe "A singleton method defined with extreme default arguments" do
|
267
|
-
|
267
|
+
it "may use a method definition as a default" do
|
268
268
|
$__a = "hi"
|
269
269
|
def $__a.foo(x = (def $__a.foo; "hello"; end;1));x;end
|
270
270
|
|
@@ -273,7 +273,7 @@ describe "A singleton method defined with extreme default arguments" do
|
|
273
273
|
$__a.foo.should == 'hello'
|
274
274
|
end
|
275
275
|
|
276
|
-
|
276
|
+
it "may use an fcall as a default" do
|
277
277
|
a = "hi"
|
278
278
|
def a.foo(x = caller())
|
279
279
|
x
|
@@ -281,14 +281,14 @@ describe "A singleton method defined with extreme default arguments" do
|
|
281
281
|
a.foo.shift.should be_kind_of(String)
|
282
282
|
end
|
283
283
|
|
284
|
-
|
284
|
+
it "evaluates the defaults in the singleton scope" do
|
285
285
|
a = "hi"
|
286
286
|
def a.foo(x = ($foo_self = self; nil)); 5 ;end
|
287
287
|
a.foo
|
288
288
|
$foo_self.should == a
|
289
289
|
end
|
290
290
|
|
291
|
-
|
291
|
+
it "may use preceding arguments as defaults" do
|
292
292
|
a = 'hi'
|
293
293
|
def a.foo(obj, width=obj.length)
|
294
294
|
width
|
@@ -296,7 +296,7 @@ describe "A singleton method defined with extreme default arguments" do
|
|
296
296
|
a.foo('abcde').should == 5
|
297
297
|
end
|
298
298
|
|
299
|
-
|
299
|
+
it "may use a lambda as a default" do
|
300
300
|
a = 'hi'
|
301
301
|
def a.foo(output = 'a', prc = lambda {|n| output * n})
|
302
302
|
prc.call(5)
|
@@ -306,7 +306,7 @@ describe "A singleton method defined with extreme default arguments" do
|
|
306
306
|
end
|
307
307
|
|
308
308
|
describe "A method definition inside a metaclass scope" do
|
309
|
-
|
309
|
+
it "can create a class method" do
|
310
310
|
class DefSpecSingleton
|
311
311
|
class << self
|
312
312
|
def a_class_method;self;end
|
@@ -339,7 +339,7 @@ describe "A method definition inside a metaclass scope" do
|
|
339
339
|
end
|
340
340
|
|
341
341
|
ruby_version_is "1.9" do
|
342
|
-
|
342
|
+
it "raises RuntimeError if frozen" do
|
343
343
|
obj = Object.new
|
344
344
|
obj.freeze
|
345
345
|
|
@@ -351,7 +351,7 @@ describe "A method definition inside a metaclass scope" do
|
|
351
351
|
end
|
352
352
|
|
353
353
|
describe "A nested method definition" do
|
354
|
-
|
354
|
+
it "creates an instance method when evaluated in an instance method" do
|
355
355
|
class DefSpecNested
|
356
356
|
def create_instance_method
|
357
357
|
def an_instance_method;self;end
|
@@ -369,7 +369,7 @@ describe "A nested method definition" do
|
|
369
369
|
DefSpecNested.should have_instance_method(:an_instance_method)
|
370
370
|
end
|
371
371
|
|
372
|
-
|
372
|
+
it "creates a class method when evaluated in a class method" do
|
373
373
|
class DefSpecNested
|
374
374
|
class << self
|
375
375
|
def create_class_method
|
@@ -386,7 +386,7 @@ describe "A nested method definition" do
|
|
386
386
|
lambda { DefSpecNested.new.a_class_method }.should raise_error(NoMethodError)
|
387
387
|
end
|
388
388
|
|
389
|
-
|
389
|
+
it "creates a singleton method when evaluated in the metaclass of an instance" do
|
390
390
|
class DefSpecNested
|
391
391
|
def create_singleton_method
|
392
392
|
class << self
|
@@ -430,7 +430,7 @@ describe "A method definition inside an instance_eval" do
|
|
430
430
|
lambda { other.a_metaclass_eval_method }.should raise_error(NoMethodError)
|
431
431
|
end
|
432
432
|
|
433
|
-
|
433
|
+
it "creates a class method when the receiver is a class" do
|
434
434
|
DefSpecNested.instance_eval do
|
435
435
|
def an_instance_eval_class_method;self;end
|
436
436
|
end
|
@@ -441,7 +441,7 @@ describe "A method definition inside an instance_eval" do
|
|
441
441
|
end
|
442
442
|
|
443
443
|
describe "A method definition in an eval" do
|
444
|
-
|
444
|
+
it "creates an instance method" do
|
445
445
|
class DefSpecNested
|
446
446
|
def eval_instance_method
|
447
447
|
eval "def an_eval_instance_method;self;end", binding
|
@@ -459,7 +459,7 @@ describe "A method definition in an eval" do
|
|
459
459
|
lambda { Object.new.an_eval_instance_method }.should raise_error(NoMethodError)
|
460
460
|
end
|
461
461
|
|
462
|
-
|
462
|
+
it "creates a class method" do
|
463
463
|
class DefSpecNestedB
|
464
464
|
class << self
|
465
465
|
def eval_class_method
|
@@ -476,7 +476,7 @@ describe "A method definition in an eval" do
|
|
476
476
|
lambda { DefSpecNestedB.new.an_eval_class_method}.should raise_error(NoMethodError)
|
477
477
|
end
|
478
478
|
|
479
|
-
|
479
|
+
it "creates a singleton method" do
|
480
480
|
class DefSpecNested
|
481
481
|
def eval_singleton_method
|
482
482
|
class << self
|
@@ -499,7 +499,7 @@ describe "a method definition that sets more than one default parameter all to t
|
|
499
499
|
def foo(a=b=c={})
|
500
500
|
[a,b,c]
|
501
501
|
end
|
502
|
-
|
502
|
+
it "assigns them all the same object by default" do
|
503
503
|
foo.should == [{},{},{}]
|
504
504
|
a, b, c = foo
|
505
505
|
a.should eql(b)
|
@@ -516,7 +516,7 @@ describe "a method definition that sets more than one default parameter all to t
|
|
516
516
|
a.should_not equal(d)
|
517
517
|
end
|
518
518
|
|
519
|
-
|
519
|
+
it "only allows overriding the default value of the first such parameter in each set" do
|
520
520
|
lambda { foo(1,2) }.should raise_error(ArgumentError)
|
521
521
|
end
|
522
522
|
|
@@ -524,7 +524,7 @@ describe "a method definition that sets more than one default parameter all to t
|
|
524
524
|
[a,b,c,d]
|
525
525
|
end
|
526
526
|
|
527
|
-
|
527
|
+
it "treats the argument after the multi-parameter normally" do
|
528
528
|
bar.should == [1,1,1,2]
|
529
529
|
bar(3).should == [3,nil,nil,2]
|
530
530
|
bar(3,4).should == [3,nil,nil,4]
|
@@ -534,7 +534,7 @@ end
|
|
534
534
|
|
535
535
|
describe "The def keyword" do
|
536
536
|
describe "within a closure" do
|
537
|
-
|
537
|
+
it "looks outside the closure for the visibility" do
|
538
538
|
module DefSpecsLambdaVisibility
|
539
539
|
private
|
540
540
|
|
@@ -45,11 +45,11 @@ describe "The defined? keyword when called with a method name" do
|
|
45
45
|
defined?(Kernel.puts).should == "method"
|
46
46
|
end
|
47
47
|
|
48
|
-
|
48
|
+
it "returns nil if the method is private" do
|
49
49
|
defined?(Object.print).should be_nil
|
50
50
|
end
|
51
51
|
|
52
|
-
|
52
|
+
it "returns nil if the method is protected" do
|
53
53
|
defined?(DefinedSpecs::Basic.new.protected_method).should be_nil
|
54
54
|
end
|
55
55
|
|
@@ -36,7 +36,7 @@ describe "An ensure block inside a begin block" do
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
|
39
|
+
it "is executed even when a symbol is thrown in it's corresponding begin block" do
|
40
40
|
begin
|
41
41
|
catch(:symbol) do
|
42
42
|
begin
|
@@ -89,7 +89,7 @@ describe "An ensure block inside a method" do
|
|
89
89
|
@obj.executed.should == [:method, :rescue, :ensure]
|
90
90
|
end
|
91
91
|
|
92
|
-
|
92
|
+
it "is executed even when a symbol is thrown in the method" do
|
93
93
|
catch(:symbol) { @obj.throw_in_method_with_ensure }
|
94
94
|
@obj.executed.should == [:method, :ensure]
|
95
95
|
end
|