summaryrefslogtreecommitdiff
path: root/spec/ruby/language
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/language')
-rw-r--r--spec/ruby/language/BEGIN_spec.rb4
-rw-r--r--spec/ruby/language/alias_spec.rb38
-rw-r--r--spec/ruby/language/and_spec.rb2
-rw-r--r--spec/ruby/language/array_spec.rb11
-rw-r--r--spec/ruby/language/block_spec.rb200
-rw-r--r--spec/ruby/language/break_spec.rb20
-rw-r--r--spec/ruby/language/case_spec.rb258
-rw-r--r--spec/ruby/language/class_spec.rb54
-rw-r--r--spec/ruby/language/class_variable_spec.rb8
-rw-r--r--spec/ruby/language/constants_spec.rb167
-rw-r--r--spec/ruby/language/def_spec.rb150
-rw-r--r--spec/ruby/language/defined_spec.rb46
-rw-r--r--spec/ruby/language/encoding_spec.rb16
-rw-r--r--spec/ruby/language/ensure_spec.rb54
-rw-r--r--spec/ruby/language/execution_spec.rb2
-rw-r--r--spec/ruby/language/file_spec.rb8
-rw-r--r--spec/ruby/language/fixtures/array.rb21
-rw-r--r--spec/ruby/language/fixtures/block.rb4
-rw-r--r--spec/ruby/language/fixtures/break.rb10
-rw-r--r--spec/ruby/language/fixtures/break_lambda_toplevel.rb2
-rw-r--r--spec/ruby/language/fixtures/break_lambda_toplevel_block.rb2
-rw-r--r--spec/ruby/language/fixtures/break_lambda_toplevel_method.rb2
-rw-r--r--spec/ruby/language/fixtures/bytes_magic_comment.rb2
-rw-r--r--spec/ruby/language/fixtures/case_magic_comment.rb2
-rw-r--r--spec/ruby/language/fixtures/def.rb6
-rw-r--r--spec/ruby/language/fixtures/defined.rb5
-rw-r--r--spec/ruby/language/fixtures/emacs_magic_comment.rb2
-rw-r--r--spec/ruby/language/fixtures/ensure.rb44
-rw-r--r--spec/ruby/language/fixtures/for_scope.rb15
-rw-r--r--spec/ruby/language/fixtures/hash_strings_ascii8bit.rb (renamed from spec/ruby/language/fixtures/hash_strings_binary.rb)4
-rw-r--r--spec/ruby/language/fixtures/magic_comment.rb2
-rw-r--r--spec/ruby/language/fixtures/metaclass.rb1
-rw-r--r--spec/ruby/language/fixtures/no_magic_comment.rb1
-rw-r--r--spec/ruby/language/fixtures/print_magic_comment_result_at_exit.rb3
-rw-r--r--spec/ruby/language/fixtures/rescue.rb4
-rw-r--r--spec/ruby/language/fixtures/second_line_magic_comment.rb3
-rw-r--r--spec/ruby/language/fixtures/second_token_magic_comment.rb2
-rw-r--r--spec/ruby/language/fixtures/send.rb3
-rwxr-xr-xspec/ruby/language/fixtures/shebang_magic_comment.rb3
-rw-r--r--spec/ruby/language/fixtures/super.rb40
-rw-r--r--spec/ruby/language/fixtures/utf16-be-nobom.rbbin68 -> 0 bytes
-rw-r--r--spec/ruby/language/fixtures/utf16-le-nobom.rbbin69 -> 0 bytes
-rw-r--r--spec/ruby/language/fixtures/utf8-bom.rb2
-rw-r--r--spec/ruby/language/fixtures/utf8-nobom.rb2
-rw-r--r--spec/ruby/language/fixtures/vim_magic_comment.rb2
-rw-r--r--spec/ruby/language/fixtures/yield.rb4
-rw-r--r--spec/ruby/language/for_spec.rb17
-rw-r--r--spec/ruby/language/hash_spec.rb33
-rw-r--r--spec/ruby/language/heredoc_spec.rb66
-rw-r--r--spec/ruby/language/if_spec.rb32
-rw-r--r--spec/ruby/language/lambda_spec.rb120
-rw-r--r--spec/ruby/language/line_spec.rb8
-rw-r--r--spec/ruby/language/loop_spec.rb4
-rw-r--r--spec/ruby/language/magic_comment_spec.rb110
-rw-r--r--spec/ruby/language/match_spec.rb11
-rw-r--r--spec/ruby/language/metaclass_spec.rb18
-rw-r--r--spec/ruby/language/method_spec.rb471
-rw-r--r--spec/ruby/language/module_spec.rb16
-rw-r--r--spec/ruby/language/next_spec.rb16
-rw-r--r--spec/ruby/language/not_spec.rb2
-rw-r--r--spec/ruby/language/numbers_spec.rb8
-rw-r--r--spec/ruby/language/optional_assignments_spec.rb137
-rw-r--r--spec/ruby/language/or_spec.rb14
-rw-r--r--spec/ruby/language/order_spec.rb2
-rw-r--r--spec/ruby/language/precedence_spec.rb39
-rw-r--r--spec/ruby/language/predefined/data_spec.rb21
-rw-r--r--spec/ruby/language/predefined/fixtures/data2.rb3
-rw-r--r--spec/ruby/language/predefined/fixtures/data3.rb3
-rw-r--r--spec/ruby/language/predefined/fixtures/data_offset.rb12
-rw-r--r--spec/ruby/language/predefined/fixtures/empty_data.rb3
-rw-r--r--spec/ruby/language/predefined/fixtures/toplevel_binding_dynamic.rb4
-rw-r--r--spec/ruby/language/predefined/fixtures/toplevel_binding_dynamic_required.rb2
-rw-r--r--spec/ruby/language/predefined/fixtures/toplevel_binding_id.rb4
-rw-r--r--spec/ruby/language/predefined/fixtures/toplevel_binding_id_required.rb1
-rw-r--r--spec/ruby/language/predefined/fixtures/toplevel_binding_required_before.rb2
-rw-r--r--spec/ruby/language/predefined/fixtures/toplevel_binding_values.rb9
-rw-r--r--spec/ruby/language/predefined/fixtures/toplevel_binding_variables.rb4
-rw-r--r--spec/ruby/language/predefined/fixtures/toplevel_binding_variables_required.rb2
-rw-r--r--spec/ruby/language/predefined/toplevel_binding_spec.rb34
-rw-r--r--spec/ruby/language/predefined_spec.rb370
-rw-r--r--spec/ruby/language/private_spec.rb18
-rw-r--r--spec/ruby/language/proc_spec.rb4
-rw-r--r--spec/ruby/language/range_spec.rb19
-rw-r--r--spec/ruby/language/redo_spec.rb6
-rw-r--r--spec/ruby/language/regexp/anchors_spec.rb4
-rw-r--r--spec/ruby/language/regexp/back-references_spec.rb11
-rw-r--r--spec/ruby/language/regexp/character_classes_spec.rb36
-rw-r--r--spec/ruby/language/regexp/encoding_spec.rb28
-rw-r--r--spec/ruby/language/regexp/escapes_spec.rb12
-rw-r--r--spec/ruby/language/regexp/grouping_spec.rb6
-rw-r--r--spec/ruby/language/regexp/interpolation_spec.rb8
-rw-r--r--spec/ruby/language/regexp/modifiers_spec.rb22
-rw-r--r--spec/ruby/language/regexp/repetition_spec.rb21
-rw-r--r--spec/ruby/language/regexp_spec.rb41
-rw-r--r--spec/ruby/language/rescue_spec.rb117
-rw-r--r--spec/ruby/language/retry_spec.rb4
-rw-r--r--spec/ruby/language/return_spec.rb58
-rw-r--r--spec/ruby/language/safe_navigator_spec.rb144
-rw-r--r--spec/ruby/language/safe_spec.rb138
-rw-r--r--spec/ruby/language/send_spec.rb75
-rw-r--r--spec/ruby/language/singleton_class_spec.rb22
-rw-r--r--spec/ruby/language/source_encoding_spec.rb61
-rw-r--r--spec/ruby/language/string_spec.rb117
-rw-r--r--spec/ruby/language/super_spec.rb189
-rw-r--r--spec/ruby/language/symbol_spec.rb4
-rw-r--r--spec/ruby/language/throw_spec.rb10
-rw-r--r--spec/ruby/language/undef_spec.rb14
-rw-r--r--spec/ruby/language/unless_spec.rb2
-rw-r--r--spec/ruby/language/until_spec.rb4
-rw-r--r--spec/ruby/language/variables_spec.rb56
-rw-r--r--spec/ruby/language/while_spec.rb4
-rw-r--r--spec/ruby/language/yield_spec.rb56
112 files changed, 1371 insertions, 2769 deletions
diff --git a/spec/ruby/language/BEGIN_spec.rb b/spec/ruby/language/BEGIN_spec.rb
index 58cc2bebfb..c0784971b0 100644
--- a/spec/ruby/language/BEGIN_spec.rb
+++ b/spec/ruby/language/BEGIN_spec.rb
@@ -1,4 +1,4 @@
-require_relative '../spec_helper'
+require File.expand_path('../../spec_helper', __FILE__)
describe "The BEGIN keyword" do
before :each do
@@ -15,7 +15,7 @@ describe "The BEGIN keyword" do
end
it "must appear in a top-level context" do
- -> { eval "1.times { BEGIN { 1 } }" }.should raise_error(SyntaxError)
+ lambda { eval "1.times { BEGIN { 1 } }" }.should raise_error(SyntaxError)
end
it "runs first in a given code unit" do
diff --git a/spec/ruby/language/alias_spec.rb b/spec/ruby/language/alias_spec.rb
index 79348f70c3..e9f0050e17 100644
--- a/spec/ruby/language/alias_spec.rb
+++ b/spec/ruby/language/alias_spec.rb
@@ -1,4 +1,4 @@
-require_relative '../spec_helper'
+require File.expand_path('../../spec_helper', __FILE__)
class AliasObject
attr :foo
@@ -38,14 +38,14 @@ describe "The alias keyword" do
@obj.a.should == 5
end
- it "works with a double quoted symbol on the left-hand side" do
+ it "works with a doubule quoted symbol on the left-hand side" do
@meta.class_eval do
alias :"a" value
end
@obj.a.should == 5
end
- it "works with an interpolated symbol on the left-hand side" do
+ it "works with an interoplated symbol on the left-hand side" do
@meta.class_eval do
alias :"#{'a'}" value
end
@@ -66,14 +66,14 @@ describe "The alias keyword" do
@obj.a.should == 5
end
- it "works with a double quoted symbol on the right-hand side" do
+ it "works with a doubule quoted symbol on the right-hand side" do
@meta.class_eval do
alias a :"value"
end
@obj.a.should == 5
end
- it "works with an interpolated symbol on the right-hand side" do
+ it "works with an interoplated symbol on the right-hand side" do
@meta.class_eval do
alias a :"#{'value'}"
end
@@ -122,7 +122,7 @@ describe "The alias keyword" do
end
@obj.__value.should == 5
- -> { AliasObject.new.__value }.should raise_error(NoMethodError)
+ lambda { AliasObject.new.__value }.should raise_error(NoMethodError)
end
it "operates on the class/module metaclass when used in instance_eval" do
@@ -131,7 +131,7 @@ describe "The alias keyword" do
end
AliasObject.__klass_method.should == 7
- -> { Object.__klass_method }.should raise_error(NoMethodError)
+ lambda { Object.__klass_method }.should raise_error(NoMethodError)
end
it "operates on the class/module metaclass when used in instance_exec" do
@@ -140,7 +140,7 @@ describe "The alias keyword" do
end
AliasObject.__klass_method2.should == 7
- -> { Object.__klass_method2 }.should raise_error(NoMethodError)
+ lambda { Object.__klass_method2 }.should raise_error(NoMethodError)
end
it "operates on methods defined via attr, attr_reader, and attr_accessor" do
@@ -204,7 +204,7 @@ describe "The alias keyword" do
end
it "operates on methods with splat arguments defined in a superclass using text block for class eval" do
- subclass = Class.new(AliasObject)
+ class Sub < AliasObject;end
AliasObject.class_eval <<-code
def test(*args)
4
@@ -215,17 +215,17 @@ describe "The alias keyword" do
alias test_without_check test
alias test test_with_check
code
- subclass.new.test("testing").should == 4
+ Sub.new.test("testing").should == 4
end
it "is not allowed against Fixnum or String instances" do
- -> do
+ lambda do
1.instance_eval do
alias :foo :to_s
end
end.should raise_error(TypeError)
- -> do
+ lambda do
:blah.instance_eval do
alias :foo :to_s
end
@@ -238,21 +238,9 @@ describe "The alias keyword" do
end
it "raises a NameError when passed a missing name" do
- -> { @meta.class_eval { alias undef_method not_exist } }.should raise_error(NameError) { |e|
+ lambda { @meta.class_eval { alias undef_method not_exist } }.should raise_error(NameError) { |e|
# a NameError and not a NoMethodError
e.class.should == NameError
}
end
end
-
-describe "The alias keyword" do
- it "can create a new global variable, synonym of the original" do
- code = '$a = 1; alias $b $a; p [$a, $b]; $b = 2; p [$a, $b]'
- ruby_exe(code).should == "[1, 1]\n[2, 2]\n"
- end
-
- it "can override an existing global variable and make them synonyms" do
- code = '$a = 1; $b = 2; alias $b $a; p [$a, $b]; $b = 3; p [$a, $b]'
- ruby_exe(code).should == "[1, 1]\n[3, 3]\n"
- end
-end
diff --git a/spec/ruby/language/and_spec.rb b/spec/ruby/language/and_spec.rb
index 55a2a3103a..e084fd3cef 100644
--- a/spec/ruby/language/and_spec.rb
+++ b/spec/ruby/language/and_spec.rb
@@ -1,4 +1,4 @@
-require_relative '../spec_helper'
+require File.expand_path('../../spec_helper', __FILE__)
describe "The '&&' statement" do
diff --git a/spec/ruby/language/array_spec.rb b/spec/ruby/language/array_spec.rb
index 2583cffbf7..c3ed8c14c5 100644
--- a/spec/ruby/language/array_spec.rb
+++ b/spec/ruby/language/array_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../spec_helper'
-require_relative 'fixtures/array'
+require File.expand_path('../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/array', __FILE__)
describe "Array literals" do
it "[] should return a new array populated with the given elements" do
@@ -36,13 +36,6 @@ describe "Array literals" do
[1, *nil, 3].should == [1, 3]
[*nil, *nil, *nil].should == []
end
-
- it "evaluates each argument exactly once" do
- se = ArraySpec::SideEffect.new
- se.array_result(true)
- se.array_result(false)
- se.call_count.should == 4
- end
end
describe "Bareword array literal" do
diff --git a/spec/ruby/language/block_spec.rb b/spec/ruby/language/block_spec.rb
index 6f92383af8..733e90211c 100644
--- a/spec/ruby/language/block_spec.rb
+++ b/spec/ruby/language/block_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../spec_helper'
-require_relative 'fixtures/block'
+require File.expand_path('../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/block', __FILE__)
describe "A block yielded a single" do
before :all do
@@ -36,7 +36,7 @@ describe "A block yielded a single" do
m([1, 2]) { |a=5, b=4, c=3| [a, b, c] }.should == [1, 2, 3]
end
- it "assigns elements to post arguments" do
+ it "assgins elements to post arguments" do
m([1, 2]) { |a=5, b, c, d| [a, b, c, d] }.should == [5, 1, 2, nil]
end
@@ -45,31 +45,25 @@ describe "A block yielded a single" do
end
it "assigns elements to mixed argument types" do
- suppress_keyword_warning do
- result = m([1, 2, 3, {x: 9}]) { |a, b=5, *c, d, e: 2, **k| [a, b, c, d, e, k] }
- result.should == [1, 2, [], 3, 2, {x: 9}]
- end
+ result = m([1, 2, 3, {x: 9}]) { |a, b=5, *c, d, e: 2, **k| [a, b, c, d, e, k] }
+ result.should == [1, 2, [], 3, 2, {x: 9}]
end
it "assigns symbol keys from a Hash to keyword arguments" do
- suppress_keyword_warning do
- result = m(["a" => 1, a: 10]) { |a=nil, **b| [a, b] }
- result.should == [{"a" => 1}, a: 10]
- end
+ result = m(["a" => 1, a: 10]) { |a=nil, **b| [a, b] }
+ result.should == [{"a" => 1}, a: 10]
end
it "assigns symbol keys from a Hash returned by #to_hash to keyword arguments" do
- suppress_keyword_warning do
- obj = mock("coerce block keyword arguments")
- obj.should_receive(:to_hash).and_return({"a" => 1, b: 2})
+ obj = mock("coerce block keyword arguments")
+ obj.should_receive(:to_hash).and_return({"a" => 1, b: 2})
- result = m([obj]) { |a=nil, **b| [a, b] }
- result.should == [{"a" => 1}, b: 2]
- end
+ result = m([obj]) { |a=nil, **b| [a, b] }
+ result.should == [{"a" => 1}, b: 2]
end
- ruby_version_is ""..."2.7" do
- it "calls #to_hash on the argument and uses resulting hash as first argument when optional argument and keyword argument accepted" do
+ ruby_version_is "2.2.1" do # SEGV on MRI 2.2.0
+ it "calls #to_hash on the argument but does not use the result when no keywords are present" do
obj = mock("coerce block keyword arguments")
obj.should_receive(:to_hash).and_return({"a" => 1, "b" => 2})
@@ -78,23 +72,9 @@ describe "A block yielded a single" do
end
end
- ruby_version_is "2.7" do
- it "calls #to_hash on the argument but ignores result when optional argument and keyword argument accepted" do
- obj = mock("coerce block keyword arguments")
- obj.should_receive(:to_hash).and_return({"a" => 1, "b" => 2})
-
- result = m([obj]) { |a=nil, **b| [a, b] }
- result.should == [obj, {}]
- end
- end
-
- describe "when non-symbol keys are in a keyword arguments Hash" do
- it "separates non-symbol keys and symbol keys" do
- suppress_keyword_warning do
- result = m(["a" => 10, b: 2]) { |a=nil, **b| [a, b] }
- result.should == [{"a" => 10}, {b: 2}]
- end
- end
+ it "assigns non-symbol keys to non-keyword arguments" do
+ result = m(["a" => 10, b: 2]) { |a=nil, **b| [a, b] }
+ result.should == [{"a" => 10}, {b: 2}]
end
it "does not treat hashes with string keys as keyword arguments" do
@@ -103,40 +83,34 @@ describe "A block yielded a single" do
end
it "calls #to_hash on the last element if keyword arguments are present" do
- suppress_keyword_warning do
- obj = mock("destructure block keyword arguments")
- obj.should_receive(:to_hash).and_return({x: 9})
+ obj = mock("destructure block keyword arguments")
+ obj.should_receive(:to_hash).and_return({x: 9})
- result = m([1, 2, 3, obj]) { |a, *b, c, **k| [a, b, c, k] }
- result.should == [1, [2], 3, {x: 9}]
- end
+ result = m([1, 2, 3, obj]) { |a, *b, c, **k| [a, b, c, k] }
+ result.should == [1, [2], 3, {x: 9}]
end
it "assigns the last element to a non-keyword argument if #to_hash returns nil" do
- suppress_keyword_warning do
- obj = mock("destructure block keyword arguments")
- obj.should_receive(:to_hash).and_return(nil)
+ obj = mock("destructure block keyword arguments")
+ obj.should_receive(:to_hash).and_return(nil)
- result = m([1, 2, 3, obj]) { |a, *b, c, **k| [a, b, c, k] }
- result.should == [1, [2, 3], obj, {}]
- end
+ result = m([1, 2, 3, obj]) { |a, *b, c, **k| [a, b, c, k] }
+ result.should == [1, [2, 3], obj, {}]
end
it "calls #to_hash on the last element when there are more arguments than parameters" do
- suppress_keyword_warning do
- x = mock("destructure matching block keyword argument")
- x.should_receive(:to_hash).and_return({x: 9})
+ x = mock("destructure matching block keyword argument")
+ x.should_receive(:to_hash).and_return({x: 9})
- result = m([1, 2, 3, {y: 9}, 4, 5, x]) { |a, b=5, c, **k| [a, b, c, k] }
- result.should == [1, 2, 3, {x: 9}]
- end
+ result = m([1, 2, 3, {y: 9}, 4, 5, x]) { |a, b=5, c, **k| [a, b, c, k] }
+ result.should == [1, 2, 3, {x: 9}]
end
it "raises a TypeError if #to_hash does not return a Hash" do
obj = mock("destructure block keyword arguments")
obj.should_receive(:to_hash).and_return(1)
- -> { m([1, 2, 3, obj]) { |a, *b, c, **k| } }.should raise_error(TypeError)
+ lambda { m([1, 2, 3, obj]) { |a, *b, c, **k| } }.should raise_error(TypeError)
end
it "raises the error raised inside #to_hash" do
@@ -144,7 +118,7 @@ describe "A block yielded a single" do
error = RuntimeError.new("error while converting to a hash")
obj.should_receive(:to_hash).and_raise(error)
- -> { m([1, 2, 3, obj]) { |a, *b, c, **k| } }.should raise_error(error)
+ lambda { m([1, 2, 3, obj]) { |a, *b, c, **k| } }.should raise_error(error)
end
it "does not call #to_ary on the Array" do
@@ -195,7 +169,7 @@ describe "A block yielded a single" do
obj = mock("destructure block arguments")
obj.should_receive(:to_ary).and_return(1)
- -> { m(obj) { |a, b| } }.should raise_error(TypeError)
+ lambda { m(obj) { |a, b| } }.should raise_error(TypeError)
end
end
end
@@ -243,12 +217,6 @@ describe "A block" do
it "does not raise an exception when values are yielded" do
@y.s(0) { 1 }.should == 1
end
-
- ruby_version_is "2.5" do
- it "may include a rescue clause" do
- eval("@y.z do raise ArgumentError; rescue ArgumentError; 7; end").should == 7
- end
- end
end
describe "taking || arguments" do
@@ -259,12 +227,6 @@ describe "A block" do
it "does not raise an exception when values are yielded" do
@y.s(0) { || 1 }.should == 1
end
-
- ruby_version_is "2.5" do
- it "may include a rescue clause" do
- eval('@y.z do || raise ArgumentError; rescue ArgumentError; 7; end').should == 7
- end
- end
end
describe "taking |a| arguments" do
@@ -290,16 +252,10 @@ describe "A block" do
it "does not destructure a single Array value" do
@y.s([1, 2]) { |a| a }.should == [1, 2]
end
-
- ruby_version_is "2.5" do
- it "may include a rescue clause" do
- eval('@y.s(1) do |x| raise ArgumentError; rescue ArgumentError; 7; end').should == 7
- end
- end
end
describe "taking |a, b| arguments" do
- it "assigns nil to the arguments when no values are yielded" do
+ it "assgins nil to the arguments when no values are yielded" do
@y.z { |a, b| [a, b] }.should == [nil, nil]
end
@@ -358,14 +314,14 @@ describe "A block" do
obj = mock("block yield to_ary invalid")
obj.should_receive(:to_ary).and_return(1)
- -> { @y.s(obj) { |a, b| } }.should raise_error(TypeError)
+ lambda { @y.s(obj) { |a, b| } }.should raise_error(TypeError)
end
it "raises the original exception if #to_ary raises an exception" do
obj = mock("block yield to_ary raising an exception")
obj.should_receive(:to_ary).and_raise(ZeroDivisionError)
- -> { @y.s(obj) { |a, b| } }.should raise_error(ZeroDivisionError)
+ lambda { @y.s(obj) { |a, b| } }.should raise_error(ZeroDivisionError)
end
end
@@ -422,7 +378,7 @@ describe "A block" do
obj = mock("block yield to_ary invalid")
obj.should_receive(:to_ary).and_return(1)
- -> { @y.s(obj) { |a, *b| } }.should raise_error(TypeError)
+ lambda { @y.s(obj) { |a, *b| } }.should raise_error(TypeError)
end
end
@@ -503,7 +459,7 @@ describe "A block" do
@y.z { |a, | a }.should be_nil
end
- it "assigns the argument a single value yielded" do
+ it "assgins the argument a single value yielded" do
@y.s(1) { |a, | a }.should == 1
end
@@ -547,7 +503,7 @@ describe "A block" do
obj = mock("block yield to_ary invalid")
obj.should_receive(:to_ary).and_return(1)
- -> { @y.s(obj) { |a, | } }.should raise_error(TypeError)
+ lambda { @y.s(obj) { |a, | } }.should raise_error(TypeError)
end
end
@@ -589,7 +545,7 @@ describe "A block" do
obj = mock("block yield to_ary invalid")
obj.should_receive(:to_ary).and_return(1)
- -> { @y.s(obj) { |(a, b)| } }.should raise_error(TypeError)
+ lambda { @y.s(obj) { |(a, b)| } }.should raise_error(TypeError)
end
end
@@ -630,7 +586,7 @@ describe "A block" do
obj = mock("block yield to_ary invalid")
obj.should_receive(:to_ary).and_return(1)
- -> { @y.s(obj) { |(a, b), c| } }.should raise_error(TypeError)
+ lambda { @y.s(obj) { |(a, b), c| } }.should raise_error(TypeError)
end
end
@@ -670,12 +626,6 @@ describe "A block" do
end
end
- describe "taking |*a, b:|" do
- it "merges the hash into the splatted array" do
- @y.k { |*a, b:| [a, b] }.should == [[], true]
- end
- end
-
describe "arguments with _" do
it "extracts arguments with _" do
@y.m([[1, 2, 3], 4]) { |(_, a, _), _| a }.should == 2
@@ -689,9 +639,9 @@ describe "A block" do
describe "taking identically-named arguments" do
it "raises a SyntaxError for standard arguments" do
- -> { eval "lambda { |x,x| }" }.should raise_error(SyntaxError)
- -> { eval "->(x,x) {}" }.should raise_error(SyntaxError)
- -> { eval "Proc.new { |x,x| }" }.should raise_error(SyntaxError)
+ lambda { eval "lambda { |x,x| }" }.should raise_error(SyntaxError)
+ lambda { eval "->(x,x) {}" }.should raise_error(SyntaxError)
+ lambda { eval "Proc.new { |x,x| }" }.should raise_error(SyntaxError)
end
it "accepts unnamed arguments" do
@@ -712,27 +662,27 @@ describe "Block-local variables" do
end
it "can not have the same name as one of the standard parameters" do
- -> { eval "[1].each {|foo; foo| }" }.should raise_error(SyntaxError)
- -> { eval "[1].each {|foo, bar; glark, bar| }" }.should raise_error(SyntaxError)
+ lambda { eval "[1].each {|foo; foo| }" }.should raise_error(SyntaxError)
+ lambda { eval "[1].each {|foo, bar; glark, bar| }" }.should raise_error(SyntaxError)
end
it "can not be prefixed with an asterisk" do
- -> { eval "[1].each {|foo; *bar| }" }.should raise_error(SyntaxError)
- -> do
+ lambda { eval "[1].each {|foo; *bar| }" }.should raise_error(SyntaxError)
+ lambda do
eval "[1].each {|foo, bar; glark, *fnord| }"
end.should raise_error(SyntaxError)
end
it "can not be prefixed with an ampersand" do
- -> { eval "[1].each {|foo; &bar| }" }.should raise_error(SyntaxError)
- -> do
+ lambda { eval "[1].each {|foo; &bar| }" }.should raise_error(SyntaxError)
+ lambda do
eval "[1].each {|foo, bar; glark, &fnord| }"
end.should raise_error(SyntaxError)
end
it "can not be assigned default values" do
- -> { eval "[1].each {|foo; bar=1| }" }.should raise_error(SyntaxError)
- -> do
+ lambda { eval "[1].each {|foo; bar=1| }" }.should raise_error(SyntaxError)
+ lambda do
eval "[1].each {|foo, bar; glark, fnord=:fnord| }"
end.should raise_error(SyntaxError)
end
@@ -743,8 +693,8 @@ describe "Block-local variables" do
end
it "only allow a single semi-colon in the parameter list" do
- -> { eval "[1].each {|foo; bar; glark| }" }.should raise_error(SyntaxError)
- -> { eval "[1].each {|; bar; glark| }" }.should raise_error(SyntaxError)
+ lambda { eval "[1].each {|foo; bar; glark| }" }.should raise_error(SyntaxError)
+ lambda { eval "[1].each {|; bar; glark| }" }.should raise_error(SyntaxError)
end
it "override shadowed variables from the outer scope" do
@@ -807,8 +757,8 @@ describe "Post-args" do
end
it "are required" do
- -> {
- -> *a, b do
+ lambda {
+ lambda do |*a, b|
[a, b]
end.call
}.should raise_error(ArgumentError)
@@ -876,38 +826,20 @@ describe "Post-args" do
end
describe "with a circular argument reference" do
- ruby_version_is ''...'2.7' do
- it "warns and uses a nil value when there is an existing local variable with same name" do
- a = 1
- -> {
- @proc = eval "proc { |a=a| a }"
- }.should complain(/circular argument reference/)
- @proc.call.should == nil
- end
-
- it "warns and uses a nil value when there is an existing method with same name" do
- def a; 1; end
- -> {
- @proc = eval "proc { |a=a| a }"
- }.should complain(/circular argument reference/)
- @proc.call.should == nil
- end
+ it "shadows an existing local with the same name as the argument" do
+ a = 1
+ -> {
+ @proc = eval "proc { |a=a| a }"
+ }.should complain(/circular argument reference/)
+ @proc.call.should == nil
end
- ruby_version_is '2.7' do
- it "raises a SyntaxError if using an existing local with the same name as the argument" do
- a = 1
- -> {
- @proc = eval "proc { |a=a| a }"
- }.should raise_error(SyntaxError)
- end
-
- it "raises a SyntaxError if there is an existing method with the same name as the argument" do
- def a; 1; end
- -> {
- @proc = eval "proc { |a=a| a }"
- }.should raise_error(SyntaxError)
- end
+ it "shadows an existing method with the same name as the argument" do
+ def a; 1; end
+ -> {
+ @proc = eval "proc { |a=a| a }"
+ }.should complain(/circular argument reference/)
+ @proc.call.should == nil
end
it "calls an existing method with the same name as the argument if explicitly using ()" do
diff --git a/spec/ruby/language/break_spec.rb b/spec/ruby/language/break_spec.rb
index 754d5d3c49..09e8ff3d93 100644
--- a/spec/ruby/language/break_spec.rb
+++ b/spec/ruby/language/break_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../spec_helper'
-require_relative 'fixtures/break'
+require File.expand_path('../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/break', __FILE__)
describe "The break statement in a block" do
before :each do
@@ -52,29 +52,29 @@ describe "The break statement in a captured block" do
describe "when the invocation of the scope creating the block is still active" do
it "raises a LocalJumpError when invoking the block from the scope creating the block" do
- -> { @program.break_in_method }.should raise_error(LocalJumpError)
+ lambda { @program.break_in_method }.should raise_error(LocalJumpError)
ScratchPad.recorded.should == [:a, :xa, :d, :b]
end
it "raises a LocalJumpError when invoking the block from a method" do
- -> { @program.break_in_nested_method }.should raise_error(LocalJumpError)
+ lambda { @program.break_in_nested_method }.should raise_error(LocalJumpError)
ScratchPad.recorded.should == [:a, :xa, :cc, :aa, :b]
end
it "raises a LocalJumpError when yielding to the block" do
- -> { @program.break_in_yielding_method }.should raise_error(LocalJumpError)
+ lambda { @program.break_in_yielding_method }.should raise_error(LocalJumpError)
ScratchPad.recorded.should == [:a, :xa, :cc, :aa, :b]
end
end
describe "from a scope that has returned" do
it "raises a LocalJumpError when calling the block from a method" do
- -> { @program.break_in_method_captured }.should raise_error(LocalJumpError)
+ lambda { @program.break_in_method_captured }.should raise_error(LocalJumpError)
ScratchPad.recorded.should == [:a, :za, :xa, :zd, :zb]
end
it "raises a LocalJumpError when yielding to the block" do
- -> { @program.break_in_yield_captured }.should raise_error(LocalJumpError)
+ lambda { @program.break_in_yield_captured }.should raise_error(LocalJumpError)
ScratchPad.recorded.should == [:a, :za, :xa, :zd, :aa, :zb]
end
end
@@ -100,7 +100,7 @@ describe "The break statement in a lambda" do
end
it "returns from the lambda" do
- l = -> {
+ l = lambda {
ScratchPad << :before
break :foo
ScratchPad << :after
@@ -111,7 +111,7 @@ describe "The break statement in a lambda" do
it "returns from the call site if the lambda is passed as a block" do
def mid(&b)
- -> {
+ lambda {
ScratchPad << :before
b.call
ScratchPad << :unreachable1
@@ -208,7 +208,7 @@ describe "Break inside a while loop" do
it "passes the value returned by a method with omitted parenthesis and passed block" do
obj = BreakSpecs::Block.new
- -> { break obj.method :value do |x| x end }.call.should == :value
+ lambda { break obj.method :value do |x| x end }.call.should == :value
end
end
diff --git a/spec/ruby/language/case_spec.rb b/spec/ruby/language/case_spec.rb
index 1475e20f75..25f5d0efc4 100644
--- a/spec/ruby/language/case_spec.rb
+++ b/spec/ruby/language/case_spec.rb
@@ -1,17 +1,17 @@
-require_relative '../spec_helper'
+require File.expand_path('../../spec_helper', __FILE__)
describe "The 'case'-construct" do
it "evaluates the body of the when clause matching the case target expression" do
case 1
- when 2; false
- when 1; true
+ when 2; false
+ when 1; true
end.should == true
end
it "evaluates the body of the when clause whose array expression includes the case target expression" do
case 2
- when 3, 4; false
- when 1, 2; true
+ when 3, 4; false
+ when 1, 2; true
end.should == true
end
@@ -21,7 +21,7 @@ describe "The 'case'-construct" do
def bar; @calls << :bar; end
case true
- when foo, bar;
+ when foo, bar;
end
@calls.should == [:foo, :bar]
@@ -29,31 +29,31 @@ describe "The 'case'-construct" do
it "evaluates the body of the when clause whose range expression includes the case target expression" do
case 5
- when 21..30; false
- when 1..20; true
+ when 21..30; false
+ when 1..20; true
end.should == true
end
it "returns nil when no 'then'-bodies are given" do
case "a"
- when "a"
- when "b"
+ when "a"
+ when "b"
end.should == nil
end
it "evaluates the 'else'-body when no other expression matches" do
case "c"
- when "a"; 'foo'
- when "b"; 'bar'
- else 'zzz'
+ when "a"; 'foo'
+ when "b"; 'bar'
+ else 'zzz'
end.should == 'zzz'
end
it "returns nil when no expression matches and 'else'-body is empty" do
case "c"
- when "a"; "a"
- when "b"; "b"
- else
+ when "a"; "a"
+ when "b"; "b"
+ else
end.should == nil
end
@@ -70,143 +70,105 @@ describe "The 'case'-construct" do
it "returns the statement following 'then'" do
case "a"
- when "a" then 'foo'
- when "b" then 'bar'
+ when "a" then 'foo'
+ when "b" then 'bar'
end.should == 'foo'
end
it "tests classes with case equality" do
case "a"
- when String
- 'foo'
- when Symbol
- 'bar'
+ when String
+ 'foo'
+ when Symbol
+ 'bar'
end.should == 'foo'
end
it "tests with matching regexps" do
case "hello"
- when /abc/; false
- when /^hell/; true
+ when /abc/; false
+ when /^hell/; true
end.should == true
end
- it "tests with matching regexps and sets $~ and captures" do
- case "foo42"
- when /oo(\d+)/
- $~.should be_kind_of(MatchData)
- $1.should == "42"
- else
- flunk
- end
- $~.should be_kind_of(MatchData)
- $1.should == "42"
- end
-
- it "tests with a regexp interpolated within another regexp" do
- digits = '\d+'
- case "foo44"
- when /oo(#{digits})/
- $~.should be_kind_of(MatchData)
- $1.should == "44"
- else
- flunk
- end
- $~.should be_kind_of(MatchData)
- $1.should == "44"
- end
-
- it "tests with a string interpolated in a regexp" do
- digits_regexp = /\d+/
- case "foo43"
- when /oo(#{digits_regexp})/
- $~.should be_kind_of(MatchData)
- $1.should == "43"
- else
- flunk
- end
- $~.should be_kind_of(MatchData)
- $1.should == "43"
- end
-
it "does not test with equality when given classes" do
case :symbol.class
- when Symbol
- "bar"
- when String
- "bar"
- else
- "foo"
+ when Symbol
+ "bar"
+ when String
+ "bar"
+ else
+ "foo"
end.should == "foo"
end
it "takes lists of values" do
case 'z'
- when 'a', 'b', 'c', 'd'
- "foo"
- when 'x', 'y', 'z'
- "bar"
+ when 'a', 'b', 'c', 'd'
+ "foo"
+ when 'x', 'y', 'z'
+ "bar"
end.should == "bar"
case 'b'
- when 'a', 'b', 'c', 'd'
- "foo"
- when 'x', 'y', 'z'
- "bar"
+ when 'a', 'b', 'c', 'd'
+ "foo"
+ when 'x', 'y', 'z'
+ "bar"
end.should == "foo"
end
it "expands arrays to lists of values" do
case 'z'
- when *['a', 'b', 'c', 'd']
- "foo"
- when *['x', 'y', 'z']
- "bar"
+ when *['a', 'b', 'c', 'd']
+ "foo"
+ when *['x', 'y', 'z']
+ "bar"
end.should == "bar"
end
it "takes an expanded array in addition to a list of values" do
case 'f'
- when 'f', *['a', 'b', 'c', 'd']
- "foo"
- when *['x', 'y', 'z']
- "bar"
+ when 'f', *['a', 'b', 'c', 'd']
+ "foo"
+ when *['x', 'y', 'z']
+ "bar"
end.should == "foo"
case 'b'
- when 'f', *['a', 'b', 'c', 'd']
- "foo"
- when *['x', 'y', 'z']
- "bar"
+ when 'f', *['a', 'b', 'c', 'd']
+ "foo"
+ when *['x', 'y', 'z']
+ "bar"
end.should == "foo"
end
it "takes an expanded array before additional listed values" do
case 'f'
- when *['a', 'b', 'c', 'd'], 'f'
- "foo"
- when *['x', 'y', 'z']
- "bar"
+ when *['a', 'b', 'c', 'd'], 'f'
+ "foo"
+ when *['x', 'y', 'z']
+ "bar"
end.should == 'foo'
end
it "expands arrays from variables before additional listed values" do
a = ['a', 'b', 'c']
case 'a'
- when *a, 'd', 'e'
- "foo"
- when 'x'
- "bar"
+ when *a, 'd', 'e'
+ "foo"
+ when 'x'
+ "bar"
end.should == "foo"
end
it "expands arrays from variables before a single additional listed value" do
a = ['a', 'b', 'c']
case 'a'
- when *a, 'd'
- "foo"
- when 'x'
- "bar"
+ when *a, 'd'
+ "foo"
+ when 'x'
+ "bar"
end.should == "foo"
end
@@ -215,10 +177,10 @@ describe "The 'case'-construct" do
b = ['d', 'e', 'f']
case 'f'
- when *a, *b, 'g', 'h'
- "foo"
- when 'x'
- "bar"
+ when *a, *b, 'g', 'h'
+ "foo"
+ when 'x'
+ "bar"
end.should == "foo"
end
@@ -228,47 +190,47 @@ describe "The 'case'-construct" do
b = ['f']
case 'f'
- when 'f', *a|b
- "foo"
- when *['x', 'y', 'z']
- "bar"
+ when 'f', *a|b
+ "foo"
+ when *['x', 'y', 'z']
+ "bar"
end.should == "foo"
end
it "never matches when clauses with no values" do
case nil
- when *[]
- "foo"
+ when *[]
+ "foo"
end.should == nil
end
it "lets you define a method after the case statement" do
case (def foo; 'foo'; end; 'f')
- when 'a'
- 'foo'
- when 'f'
- 'bar'
+ when 'a'
+ 'foo'
+ when 'f'
+ 'bar'
end.should == 'bar'
end
it "raises a SyntaxError when 'else' is used when no 'when' is given" do
- -> {
+ lambda {
eval <<-CODE
case 4
- else
- true
+ else
+ true
end
CODE
}.should raise_error(SyntaxError)
end
it "raises a SyntaxError when 'else' is used before a 'when' was given" do
- -> {
+ lambda {
eval <<-CODE
case 4
- else
- true
- when 4; false
+ else
+ true
+ when 4; false
end
CODE
}.should raise_error(SyntaxError)
@@ -325,56 +287,56 @@ end
describe "The 'case'-construct with no target expression" do
it "evaluates the body of the first clause when at least one of its condition expressions is true" do
case
- when true, false; 'foo'
+ when true, false; 'foo'
end.should == 'foo'
end
it "evaluates the body of the first when clause that is not false/nil" do
case
- when false; 'foo'
- when 2; 'bar'
- when 1 == 1; 'baz'
+ when false; 'foo'
+ when 2; 'bar'
+ when 1 == 1; 'baz'
end.should == 'bar'
case
- when false; 'foo'
- when nil; 'foo'
- when 1 == 1; 'bar'
+ when false; 'foo'
+ when nil; 'foo'
+ when 1 == 1; 'bar'
end.should == 'bar'
end
it "evaluates the body of the else clause if all when clauses are false/nil" do
case
- when false; 'foo'
- when nil; 'foo'
- when 1 == 2; 'bar'
- else 'baz'
+ when false; 'foo'
+ when nil; 'foo'
+ when 1 == 2; 'bar'
+ else 'baz'
end.should == 'baz'
end
it "evaluates multiple conditional expressions as a boolean disjunction" do
case
- when true, false; 'foo'
- else 'bar'
+ when true, false; 'foo'
+ else 'bar'
end.should == 'foo'
case
- when false, true; 'foo'
- else 'bar'
+ when false, true; 'foo'
+ else 'bar'
end.should == 'foo'
end
it "evaluates true as only 'true' when true is the first clause" do
case 1
- when true; "bad"
- when Integer; "good"
+ when true; "bad"
+ when Integer; "good"
end.should == "good"
end
it "evaluates false as only 'false' when false is the first clause" do
case nil
- when false; "bad"
- when nil; "good"
+ when false; "bad"
+ when nil; "good"
end.should == "good"
end
@@ -390,17 +352,17 @@ describe "The 'case'-construct with no target expression" do
a2 = ['b', 'a', 'r']
case 'f'
- when *a1, *['x', 'y', 'z']
- "foo"
- when *a2, *['x', 'y', 'z']
- "bar"
+ when *a1, *['x', 'y', 'z']
+ "foo"
+ when *a2, *['x', 'y', 'z']
+ "bar"
end.should == "foo"
case 'b'
- when *a1, *['x', 'y', 'z']
- "foo"
- when *a2, *['x', 'y', 'z']
- "bar"
+ when *a1, *['x', 'y', 'z']
+ "foo"
+ when *a2, *['x', 'y', 'z']
+ "bar"
end.should == "bar"
end
diff --git a/spec/ruby/language/class_spec.rb b/spec/ruby/language/class_spec.rb
index 88b7a6a74f..ba4af3d880 100644
--- a/spec/ruby/language/class_spec.rb
+++ b/spec/ruby/language/class_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/class'
+require File.expand_path('../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/class', __FILE__)
ClassSpecsNumber = 12
@@ -13,9 +13,11 @@ describe "The class keyword" do
ClassSpecsKeywordWithSemicolon.should be_an_instance_of(Class)
end
- it "does not raise a SyntaxError when opening a class without a semicolon" do
- eval "class ClassSpecsKeywordWithoutSemicolon end"
- ClassSpecsKeywordWithoutSemicolon.should be_an_instance_of(Class)
+ ruby_version_is "2.3" do
+ it "does not raise a SyntaxError when opening a class without a semicolon" do
+ eval "class ClassSpecsKeywordWithoutSemicolon end"
+ ClassSpecsKeywordWithoutSemicolon.should be_an_instance_of(Class)
+ end
end
end
@@ -30,7 +32,7 @@ describe "A class definition" do
end
it "raises TypeError if constant given as class name exists and is not a Module" do
- -> {
+ lambda {
class ClassSpecsNumber
end
}.should raise_error(TypeError)
@@ -38,19 +40,19 @@ describe "A class definition" do
# test case known to be detecting bugs (JRuby, MRI)
it "raises TypeError if the constant qualifying the class is nil" do
- -> {
+ lambda {
class nil::Foo
end
}.should raise_error(TypeError)
end
it "raises TypeError if any constant qualifying the class is not a Module" do
- -> {
+ lambda {
class ClassSpecs::Number::MyClass
end
}.should raise_error(TypeError)
- -> {
+ lambda {
class ClassSpecsNumber::MyClass
end
}.should raise_error(TypeError)
@@ -64,7 +66,7 @@ describe "A class definition" do
module ClassSpecs
class SuperclassResetToSubclass < L
end
- -> {
+ lambda {
class SuperclassResetToSubclass < M
end
}.should raise_error(TypeError, /superclass mismatch/)
@@ -77,7 +79,7 @@ describe "A class definition" do
end
SuperclassReopenedBasicObject.superclass.should == A
- -> {
+ lambda {
class SuperclassReopenedBasicObject < BasicObject
end
}.should raise_error(TypeError, /superclass mismatch/)
@@ -92,7 +94,7 @@ describe "A class definition" do
end
SuperclassReopenedObject.superclass.should == A
- -> {
+ lambda {
class SuperclassReopenedObject < Object
end
}.should raise_error(TypeError, /superclass mismatch/)
@@ -117,7 +119,7 @@ describe "A class definition" do
class NoSuperclassSet
end
- -> {
+ lambda {
class NoSuperclassSet < String
end
}.should raise_error(TypeError, /superclass mismatch/)
@@ -127,7 +129,7 @@ describe "A class definition" do
it "allows using self as the superclass if self is a class" do
ClassSpecs::I::J.superclass.should == ClassSpecs::I
- -> {
+ lambda {
class ShouldNotWork < self; end
}.should raise_error(TypeError)
end
@@ -148,7 +150,7 @@ describe "A class definition" do
it "raises a TypeError if inheriting from a metaclass" do
obj = mock("metaclass super")
meta = obj.singleton_class
- -> { class ClassSpecs::MetaclassSuper < meta; end }.should raise_error(TypeError)
+ lambda { class ClassSpecs::MetaclassSuper < meta; end }.should raise_error(TypeError)
end
it "allows the declaration of class variables in the body" do
@@ -210,16 +212,16 @@ describe "A class definition" do
describe "within a block creates a new class in the lexical scope" do
it "for named classes at the toplevel" do
klass = Class.new do
- class CS_CONST_CLASS_SPECS
+ class Howdy
end
def self.get_class_name
- CS_CONST_CLASS_SPECS.name
+ Howdy.name
end
end
- klass.get_class_name.should == 'CS_CONST_CLASS_SPECS'
- ::CS_CONST_CLASS_SPECS.name.should == 'CS_CONST_CLASS_SPECS'
+ Howdy.name.should == 'Howdy'
+ klass.get_class_name.should == 'Howdy'
end
it "for named classes in a module" do
@@ -274,7 +276,7 @@ describe "A class definition extending an object (sclass)" do
end
it "raises a TypeError when trying to extend numbers" do
- -> {
+ lambda {
eval <<-CODE
class << 1
def xyz
@@ -285,12 +287,8 @@ describe "A class definition extending an object (sclass)" do
}.should raise_error(TypeError)
end
- ruby_version_is ""..."3.0" do
- it "allows accessing the block of the original scope" do
- suppress_warning do
- ClassSpecs.sclass_with_block { 123 }.should == 123
- end
- end
+ it "allows accessing the block of the original scope" do
+ ClassSpecs.sclass_with_block { 123 }.should == 123
end
it "can use return to cause the enclosing method to return" do
@@ -310,11 +308,11 @@ describe "Reopening a class" do
end
it "raises a TypeError when superclasses mismatch" do
- -> { class ClassSpecs::A < Array; end }.should raise_error(TypeError)
+ lambda { class ClassSpecs::A < Array; end }.should raise_error(TypeError)
end
it "adds new methods to subclasses" do
- -> { ClassSpecs::M.m }.should raise_error(NoMethodError)
+ lambda { ClassSpecs::M.m }.should raise_error(NoMethodError)
class ClassSpecs::L
def self.m
1
diff --git a/spec/ruby/language/class_variable_spec.rb b/spec/ruby/language/class_variable_spec.rb
index dffab47a6b..463f731a93 100644
--- a/spec/ruby/language/class_variable_spec.rb
+++ b/spec/ruby/language/class_variable_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/class_variables'
+require File.expand_path('../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/class_variables', __FILE__)
describe "A class variable" do
after :each do
@@ -70,14 +70,14 @@ describe 'A class variable definition' do
c = Class.new(b)
b.class_variable_set(:@@cv, :value)
- -> { a.class_variable_get(:@@cv) }.should raise_error(NameError)
+ lambda { a.class_variable_get(:@@cv) }.should raise_error(NameError)
b.class_variable_get(:@@cv).should == :value
c.class_variable_get(:@@cv).should == :value
# updates the same variable
c.class_variable_set(:@@cv, :next)
- -> { a.class_variable_get(:@@cv) }.should raise_error(NameError)
+ lambda { a.class_variable_get(:@@cv) }.should raise_error(NameError)
b.class_variable_get(:@@cv).should == :next
c.class_variable_get(:@@cv).should == :next
end
diff --git a/spec/ruby/language/constants_spec.rb b/spec/ruby/language/constants_spec.rb
index c4cf940cba..1f1e254fb8 100644
--- a/spec/ruby/language/constants_spec.rb
+++ b/spec/ruby/language/constants_spec.rb
@@ -1,7 +1,7 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/constants'
-require_relative 'fixtures/constants_sclass'
-require_relative 'fixtures/constant_visibility'
+require File.expand_path('../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/constants', __FILE__)
+require File.expand_path('../fixtures/constants_sclass', __FILE__)
+require File.expand_path('../fixtures/constant_visibility', __FILE__)
# Read the documentation in fixtures/constants.rb for the guidelines and
# rationale for the structure and organization of these specs.
@@ -49,10 +49,10 @@ describe "Literal (A::X) constant resolution" do
end
it "does not search the singleton class of the class or module" do
- -> do
+ lambda do
ConstantSpecs::ContainerA::ChildA::CS_CONST14
end.should raise_error(NameError)
- -> { ConstantSpecs::CS_CONST14 }.should raise_error(NameError)
+ lambda { ConstantSpecs::CS_CONST14 }.should raise_error(NameError)
end
end
@@ -112,7 +112,7 @@ describe "Literal (A::X) constant resolution" do
CS_CONST108 = :const108_1
end
- -> do
+ lambda do
ConstantSpecs::ContainerB::ChildB::CS_CONST108
end.should raise_error(NameError)
@@ -122,7 +122,7 @@ describe "Literal (A::X) constant resolution" do
end
end
- -> { ConstantSpecs::CS_CONST108 }.should raise_error(NameError)
+ lambda { ConstantSpecs::CS_CONST108 }.should raise_error(NameError)
end
it "returns the updated value when a constant is reassigned" do
@@ -151,7 +151,7 @@ describe "Literal (A::X) constant resolution" do
end
it "raises a NameError if no constant is defined in the search path" do
- -> { ConstantSpecs::ParentA::CS_CONSTX }.should raise_error(NameError)
+ lambda { ConstantSpecs::ParentA::CS_CONSTX }.should raise_error(NameError)
end
it "sends #const_missing to the original class or module scope" do
@@ -163,10 +163,10 @@ describe "Literal (A::X) constant resolution" do
end
it "raises a TypeError if a non-class or non-module qualifier is given" do
- -> { CS_CONST1::CS_CONST }.should raise_error(TypeError)
- -> { 1::CS_CONST }.should raise_error(TypeError)
- -> { "mod"::CS_CONST }.should raise_error(TypeError)
- -> { false::CS_CONST }.should raise_error(TypeError)
+ lambda { CS_CONST1::CS_CONST }.should raise_error(TypeError)
+ lambda { 1::CS_CONST }.should raise_error(TypeError)
+ lambda { "mod"::CS_CONST }.should raise_error(TypeError)
+ lambda { false::CS_CONST }.should raise_error(TypeError)
end
end
@@ -212,7 +212,7 @@ describe "Constant resolution within methods" do
end
it "does not search the lexical scope of the caller" do
- -> { ConstantSpecs::ClassA.const16 }.should raise_error(NameError)
+ lambda { ConstantSpecs::ClassA.const16 }.should raise_error(NameError)
end
it "searches the lexical scope of a block" do
@@ -225,7 +225,7 @@ describe "Constant resolution within methods" do
end
it "does not search the lexical scope of qualifying modules" do
- -> do
+ lambda do
ConstantSpecs::ContainerA::ChildA.const23
end.should raise_error(NameError)
end
@@ -302,7 +302,7 @@ describe "Constant resolution within methods" do
it "does not search the lexical scope of the caller" do
ConstantSpecs::ClassB::CS_CONST209 = :const209
- -> { ConstantSpecs::ClassB.const209 }.should raise_error(NameError)
+ lambda { ConstantSpecs::ClassB.const209 }.should raise_error(NameError)
end
it "searches the lexical scope of a block" do
@@ -337,14 +337,14 @@ describe "Constant resolution within methods" do
it "does not search the lexical scope of qualifying modules" do
ConstantSpecs::ContainerB::CS_CONST214 = :const214
- -> do
+ lambda do
ConstantSpecs::ContainerB::ChildB.const214
end.should raise_error(NameError)
end
end
it "raises a NameError if no constant is defined in the search path" do
- -> { ConstantSpecs::ParentA.constx }.should raise_error(NameError)
+ lambda { ConstantSpecs::ParentA.constx }.should raise_error(NameError)
end
it "sends #const_missing to the original class or module scope" do
@@ -404,22 +404,24 @@ describe "Constant resolution within a singleton class (class << obj)" do
ConstantSpecs::CS_SINGLETON1.foo.should == 1
end
- it "uses its own namespace for each object" do
- a = ConstantSpecs::CS_SINGLETON2[0].foo
- b = ConstantSpecs::CS_SINGLETON2[1].foo
- [a, b].should == [1, 2]
- end
+ ruby_version_is "2.3" do
+ it "uses its own namespace for each object" do
+ a = ConstantSpecs::CS_SINGLETON2[0].foo
+ b = ConstantSpecs::CS_SINGLETON2[1].foo
+ [a, b].should == [1, 2]
+ end
- it "uses its own namespace for nested modules" do
- a = ConstantSpecs::CS_SINGLETON3[0].x
- b = ConstantSpecs::CS_SINGLETON3[1].x
- a.should_not equal(b)
- end
+ it "uses its own namespace for nested modules" do
+ a = ConstantSpecs::CS_SINGLETON3[0].x
+ b = ConstantSpecs::CS_SINGLETON3[1].x
+ a.should_not equal(b)
+ end
- it "allows nested modules to have proper resolution" do
- a = ConstantSpecs::CS_SINGLETON4_CLASSES[0].new
- b = ConstantSpecs::CS_SINGLETON4_CLASSES[1].new
- [a.foo, b.foo].should == [1, 2]
+ it "allows nested modules to have proper resolution" do
+ a = ConstantSpecs::CS_SINGLETON4_CLASSES[0].new
+ b = ConstantSpecs::CS_SINGLETON4_CLASSES[1].new
+ [a.foo, b.foo].should == [1, 2]
+ end
end
end
@@ -427,7 +429,7 @@ describe "top-level constant lookup" do
context "on a class" do
ruby_version_is "" ... "2.5" do
it "searches Object successfully after searching other scopes" do
- -> {
+ ->() {
String::Hash.should == Hash
}.should complain(/toplevel constant Hash referenced by/)
end
@@ -435,13 +437,13 @@ describe "top-level constant lookup" do
ruby_version_is "2.5" do
it "does not search Object after searching other scopes" do
- -> { String::Hash }.should raise_error(NameError)
+ ->() { String::Hash }.should raise_error(NameError)
end
end
end
it "searches Object unsuccessfully when searches on a module" do
- -> { Enumerable::Hash }.should raise_error(NameError)
+ ->() { Enumerable::Hash }.should raise_error(NameError)
end
end
@@ -455,37 +457,24 @@ describe "Module#private_constant marked constants" do
mod.const_set :Foo, false
}.should complain(/already initialized constant/)
- -> {mod::Foo}.should raise_error(NameError)
- end
-
- ruby_version_is "2.6" do
- it "sends #const_missing to the original class or module" do
- mod = Module.new
- mod.const_set :Foo, true
- mod.send :private_constant, :Foo
- def mod.const_missing(name)
- name == :Foo ? name : super
- end
-
- mod::Foo.should == :Foo
- end
+ lambda {mod::Foo}.should raise_error(NameError)
end
describe "in a module" do
it "cannot be accessed from outside the module" do
- -> do
+ lambda do
ConstantVisibility::PrivConstModule::PRIVATE_CONSTANT_MODULE
end.should raise_error(NameError)
end
it "cannot be reopened as a module from scope where constant would be private" do
- -> do
+ lambda do
module ConstantVisibility::ModuleContainer::PrivateModule; end
end.should raise_error(NameError)
end
it "cannot be reopened as a class from scope where constant would be private" do
- -> do
+ lambda do
class ConstantVisibility::ModuleContainer::PrivateClass; end
end.should raise_error(NameError)
end
@@ -541,19 +530,19 @@ describe "Module#private_constant marked constants" do
describe "in a class" do
it "cannot be accessed from outside the class" do
- -> do
+ lambda do
ConstantVisibility::PrivConstClass::PRIVATE_CONSTANT_CLASS
end.should raise_error(NameError)
end
it "cannot be reopened as a module" do
- -> do
+ lambda do
module ConstantVisibility::ClassContainer::PrivateModule; end
end.should raise_error(NameError)
end
it "cannot be reopened as a class" do
- -> do
+ lambda do
class ConstantVisibility::ClassContainer::PrivateClass; end
end.should raise_error(NameError)
end
@@ -609,7 +598,7 @@ describe "Module#private_constant marked constants" do
describe "in Object" do
it "cannot be accessed using ::Const form" do
- -> do
+ lambda do
::PRIVATE_CONSTANT_IN_OBJECT
end.should raise_error(NameError)
end
@@ -626,40 +615,6 @@ describe "Module#private_constant marked constants" do
defined?(PRIVATE_CONSTANT_IN_OBJECT).should == "constant"
end
end
-
- describe "NameError by #private_constant" do
- it "has :receiver and :name attributes" do
- -> do
- ConstantVisibility::PrivConstClass::PRIVATE_CONSTANT_CLASS
- end.should raise_error(NameError) {|e|
- e.receiver.should == ConstantVisibility::PrivConstClass
- e.name.should == :PRIVATE_CONSTANT_CLASS
- }
-
- -> do
- ConstantVisibility::PrivConstModule::PRIVATE_CONSTANT_MODULE
- end.should raise_error(NameError) {|e|
- e.receiver.should == ConstantVisibility::PrivConstModule
- e.name.should == :PRIVATE_CONSTANT_MODULE
- }
- end
-
- it "has the defined class as the :name attribute" do
- -> do
- ConstantVisibility::PrivConstClassChild::PRIVATE_CONSTANT_CLASS
- end.should raise_error(NameError) {|e|
- e.receiver.should == ConstantVisibility::PrivConstClass
- e.name.should == :PRIVATE_CONSTANT_CLASS
- }
-
- -> do
- ConstantVisibility::PrivConstModuleChild::PRIVATE_CONSTANT_MODULE
- end.should raise_error(NameError) {|e|
- e.receiver.should == ConstantVisibility::PrivConstModule
- e.name.should == :PRIVATE_CONSTANT_MODULE
- }
- end
- end
end
describe "Module#public_constant marked constants" do
@@ -711,35 +666,3 @@ describe "Module#public_constant marked constants" do
end
end
end
-
-describe 'Allowed characters' do
- it 'allows not ASCII characters in the middle of a name' do
- mod = Module.new
- mod.const_set("BBá¼BB", 1)
-
- eval("mod::BBá¼BB").should == 1
- end
-
- it 'does not allow not ASCII characters that cannot be upcased or lowercased at the beginning' do
- -> do
- Module.new.const_set("થBB", 1)
- end.should raise_error(NameError, /wrong constant name/)
- end
-
- ruby_version_is ""..."2.6" do
- it 'does not allow not ASCII upcased characters at the beginning' do
- -> do
- Module.new.const_set("á¼BB", 1)
- end.should raise_error(NameError, /wrong constant name/)
- end
- end
-
- ruby_version_is "2.6" do
- it 'allows not ASCII upcased characters at the beginning' do
- mod = Module.new
- mod.const_set("á¼BB", 1)
-
- eval("mod::á¼BB").should == 1
- end
- end
-end
diff --git a/spec/ruby/language/def_spec.rb b/spec/ruby/language/def_spec.rb
index fc5693a2f0..55ee283b90 100644
--- a/spec/ruby/language/def_spec.rb
+++ b/spec/ruby/language/def_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../spec_helper'
-require_relative 'fixtures/def'
+require File.expand_path('../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/def', __FILE__)
# Language-level method behaviour
describe "Redefining a method" do
@@ -79,18 +79,6 @@ describe "Defining a method" do
end
end
-describe "An instance method" do
- it "raises an error with too few arguments" do
- def foo(a, b); end
- -> { foo 1 }.should raise_error(ArgumentError, 'wrong number of arguments (given 1, expected 2)')
- end
-
- it "raises an error with too many arguments" do
- def foo(a); end
- -> { foo 1, 2 }.should raise_error(ArgumentError, 'wrong number of arguments (given 2, expected 1)')
- end
-end
-
describe "An instance method definition with a splat" do
it "accepts an unnamed '*' argument" do
def foo(*); end;
@@ -113,12 +101,12 @@ describe "An instance method definition with a splat" do
end
it "allows only a single * argument" do
- -> { eval 'def foo(a, *b, *c); end' }.should raise_error(SyntaxError)
+ lambda { eval 'def foo(a, *b, *c); end' }.should raise_error(SyntaxError)
end
it "requires the presence of any arguments that precede the *" do
def foo(a, b, *c); end
- -> { foo 1 }.should raise_error(ArgumentError, 'wrong number of arguments (given 1, expected 2+)')
+ lambda { foo 1 }.should raise_error(ArgumentError)
end
end
@@ -151,7 +139,7 @@ describe "An instance method with a default argument" do
def foo(a, b = 2)
[a,b]
end
- -> { foo }.should raise_error(ArgumentError, 'wrong number of arguments (given 0, expected 1..2)')
+ lambda { foo }.should raise_error(ArgumentError)
foo(1).should == [1, 2]
end
@@ -159,7 +147,7 @@ describe "An instance method with a default argument" do
def foo(a, b = 2, *c)
[a,b,c]
end
- -> { foo }.should raise_error(ArgumentError, 'wrong number of arguments (given 0, expected 1+)')
+ lambda { foo }.should raise_error(ArgumentError)
foo(1).should == [1,2,[]]
end
@@ -177,32 +165,17 @@ describe "An instance method with a default argument" do
foo(2,3,3).should == [2,3,[3]]
end
- ruby_version_is ''...'2.7' do
- it "warns and uses a nil value when there is an existing local method with same name" do
- def bar
- 1
- end
- -> {
- eval "def foo(bar = bar)
- bar
- end"
- }.should complain(/circular argument reference/)
- foo.should == nil
- foo(2).should == 2
- end
- end
-
- ruby_version_is '2.7' do
- it "raises a syntaxError an existing method with the same name as the local variable" do
- def bar
- 1
- end
- -> {
- eval "def foo(bar = bar)
- bar
- end"
- }.should raise_error(SyntaxError)
+ it "shadows an existing method with the same name as the local" do
+ def bar
+ 1
end
+ -> {
+ eval "def foo(bar = bar)
+ bar
+ end"
+ }.should complain(/circular argument reference/)
+ foo.should == nil
+ foo(2).should == 2
end
it "calls a method with the same name as the local when explicitly using ()" do
@@ -261,10 +234,10 @@ describe "A singleton method definition" do
(obj==2).should == 2
end
- it "raises #{frozen_error_class} if frozen" do
+ it "raises RuntimeError if frozen" do
obj = Object.new
obj.freeze
- -> { def obj.foo; end }.should raise_error(frozen_error_class)
+ lambda { def obj.foo; end }.should raise_error(RuntimeError)
end
end
@@ -337,7 +310,7 @@ describe "A method defined with extreme default arguments" do
end
it "may use a lambda as a default" do
- def foo(output = 'a', prc = -> n { output * n })
+ def foo(output = 'a', prc = lambda {|n| output * n})
prc.call(5)
end
foo.should == 'aaaaa'
@@ -383,7 +356,7 @@ describe "A singleton method defined with extreme default arguments" do
it "may use a lambda as a default" do
a = Object.new
- def a.foo(output = 'a', prc = -> n { output * n })
+ def a.foo(output = 'a', prc = lambda {|n| output * n})
prc.call(5)
end
a.foo.should == 'aaaaa'
@@ -399,7 +372,7 @@ describe "A method definition inside a metaclass scope" do
end
DefSpecSingleton.a_class_method.should == DefSpecSingleton
- -> { Object.a_class_method }.should raise_error(NoMethodError)
+ lambda { Object.a_class_method }.should raise_error(NoMethodError)
end
it "can create a singleton method" do
@@ -409,15 +382,15 @@ describe "A method definition inside a metaclass scope" do
end
obj.a_singleton_method.should == obj
- -> { Object.new.a_singleton_method }.should raise_error(NoMethodError)
+ lambda { Object.new.a_singleton_method }.should raise_error(NoMethodError)
end
- it "raises #{frozen_error_class} if frozen" do
+ it "raises RuntimeError if frozen" do
obj = Object.new
obj.freeze
class << obj
- -> { def foo; end }.should raise_error(frozen_error_class)
+ lambda { def foo; end }.should raise_error(RuntimeError)
end
end
end
@@ -453,11 +426,11 @@ describe "A nested method definition" do
end
end
- -> { DefSpecNested.a_class_method }.should raise_error(NoMethodError)
+ lambda { DefSpecNested.a_class_method }.should raise_error(NoMethodError)
DefSpecNested.create_class_method.should == DefSpecNested
DefSpecNested.a_class_method.should == DefSpecNested
- -> { Object.a_class_method }.should raise_error(NoMethodError)
- -> { DefSpecNested.new.a_class_method }.should raise_error(NoMethodError)
+ lambda { Object.a_class_method }.should raise_error(NoMethodError)
+ lambda { DefSpecNested.new.a_class_method }.should raise_error(NoMethodError)
end
it "creates a singleton method when evaluated in the metaclass of an instance" do
@@ -475,7 +448,7 @@ describe "A nested method definition" do
obj.a_singleton_method.should == obj
other = DefSpecNested.new
- -> { other.a_singleton_method }.should raise_error(NoMethodError)
+ lambda { other.a_singleton_method }.should raise_error(NoMethodError)
end
it "creates a method in the surrounding context when evaluated in a def expr.method" do
@@ -515,7 +488,7 @@ describe "A nested method definition" do
DefSpecNested.should_not have_instance_method :body_method
end
- it "creates an instance method inside Class.new" do
+ it "defines methods as public by default" do
cls = Class.new do
def do_def
def new_def
@@ -527,41 +500,6 @@ describe "A nested method definition" do
obj = cls.new
obj.do_def
obj.new_def.should == 1
-
- cls.new.new_def.should == 1
-
- -> { Object.new.new_def }.should raise_error(NoMethodError)
- end
-end
-
-describe "A method definition always resets the visibility to public for nested definitions" do
- it "in Class.new" do
- cls = Class.new do
- private
- def do_def
- def new_def
- 1
- end
- end
- end
-
- obj = cls.new
- -> { obj.do_def }.should raise_error(NoMethodError, /private/)
- obj.send :do_def
- obj.new_def.should == 1
-
- cls.new.new_def.should == 1
-
- -> { Object.new.new_def }.should raise_error(NoMethodError)
- end
-
- it "at the toplevel" do
- obj = Object.new
- -> { obj.toplevel_define_other_method }.should raise_error(NoMethodError, /private/)
- toplevel_define_other_method
- nested_method_in_toplevel_method.should == 42
-
- Object.new.nested_method_in_toplevel_method.should == 42
end
end
@@ -574,7 +512,7 @@ describe "A method definition inside an instance_eval" do
obj.an_instance_eval_method.should == obj
other = Object.new
- -> { other.an_instance_eval_method }.should raise_error(NoMethodError)
+ lambda { other.an_instance_eval_method }.should raise_error(NoMethodError)
end
it "creates a singleton method when evaluated inside a metaclass" do
@@ -587,7 +525,7 @@ describe "A method definition inside an instance_eval" do
obj.a_metaclass_eval_method.should == obj
other = Object.new
- -> { other.a_metaclass_eval_method }.should raise_error(NoMethodError)
+ lambda { other.a_metaclass_eval_method }.should raise_error(NoMethodError)
end
it "creates a class method when the receiver is a class" do
@@ -596,7 +534,7 @@ describe "A method definition inside an instance_eval" do
end
DefSpecNested.an_instance_eval_class_method.should == DefSpecNested
- -> { Object.an_instance_eval_class_method }.should raise_error(NoMethodError)
+ lambda { Object.an_instance_eval_class_method }.should raise_error(NoMethodError)
end
it "creates a class method when the receiver is an anonymous class" do
@@ -608,7 +546,7 @@ describe "A method definition inside an instance_eval" do
end
m.klass_method.should == :test
- -> { Object.klass_method }.should raise_error(NoMethodError)
+ lambda { Object.klass_method }.should raise_error(NoMethodError)
end
it "creates a class method when instance_eval is within class" do
@@ -621,7 +559,7 @@ describe "A method definition inside an instance_eval" do
end
m.klass_method.should == :test
- -> { Object.klass_method }.should raise_error(NoMethodError)
+ lambda { Object.klass_method }.should raise_error(NoMethodError)
end
end
@@ -634,7 +572,7 @@ describe "A method definition inside an instance_exec" do
end
DefSpecNested.an_instance_exec_class_method.should == 1
- -> { Object.an_instance_exec_class_method }.should raise_error(NoMethodError)
+ lambda { Object.an_instance_exec_class_method }.should raise_error(NoMethodError)
end
it "creates a class method when the receiver is an anonymous class" do
@@ -648,7 +586,7 @@ describe "A method definition inside an instance_exec" do
end
m.klass_method.should == 1
- -> { Object.klass_method }.should raise_error(NoMethodError)
+ lambda { Object.klass_method }.should raise_error(NoMethodError)
end
it "creates a class method when instance_exec is within class" do
@@ -663,7 +601,7 @@ describe "A method definition inside an instance_exec" do
end
m.klass_method.should == 2
- -> { Object.klass_method }.should raise_error(NoMethodError)
+ lambda { Object.klass_method }.should raise_error(NoMethodError)
end
end
@@ -683,7 +621,7 @@ describe "A method definition in an eval" do
other = DefSpecNested.new
other.an_eval_instance_method.should == other
- -> { Object.new.an_eval_instance_method }.should raise_error(NoMethodError)
+ lambda { Object.new.an_eval_instance_method }.should raise_error(NoMethodError)
end
it "creates a class method" do
@@ -699,8 +637,8 @@ describe "A method definition in an eval" do
DefSpecNestedB.eval_class_method.should == DefSpecNestedB
DefSpecNestedB.an_eval_class_method.should == DefSpecNestedB
- -> { Object.an_eval_class_method }.should raise_error(NoMethodError)
- -> { DefSpecNestedB.new.an_eval_class_method}.should raise_error(NoMethodError)
+ lambda { Object.an_eval_class_method }.should raise_error(NoMethodError)
+ lambda { DefSpecNestedB.new.an_eval_class_method}.should raise_error(NoMethodError)
end
it "creates a singleton method" do
@@ -718,7 +656,7 @@ describe "A method definition in an eval" do
obj.an_eval_singleton_method.should == obj
other = DefSpecNested.new
- -> { other.an_eval_singleton_method }.should raise_error(NoMethodError)
+ lambda { other.an_eval_singleton_method }.should raise_error(NoMethodError)
end
end
@@ -744,7 +682,7 @@ describe "a method definition that sets more than one default parameter all to t
end
it "only allows overriding the default value of the first such parameter in each set" do
- -> { foo(1,2) }.should raise_error(ArgumentError, 'wrong number of arguments (given 2, expected 0..1)')
+ lambda { foo(1,2) }.should raise_error(ArgumentError)
end
def bar(a=b=c=1,d=2)
@@ -755,7 +693,7 @@ describe "a method definition that sets more than one default parameter all to t
bar.should == [1,1,1,2]
bar(3).should == [3,nil,nil,2]
bar(3,4).should == [3,nil,nil,4]
- -> { bar(3,4,5) }.should raise_error(ArgumentError, 'wrong number of arguments (given 3, expected 0..2)')
+ lambda { bar(3,4,5) }.should raise_error(ArgumentError)
end
end
@@ -765,7 +703,7 @@ describe "The def keyword" do
module DefSpecsLambdaVisibility
private
- -> {
+ lambda {
def some_method; end
}.call
end
diff --git a/spec/ruby/language/defined_spec.rb b/spec/ruby/language/defined_spec.rb
index 02c69d27b8..9fe460a9de 100644
--- a/spec/ruby/language/defined_spec.rb
+++ b/spec/ruby/language/defined_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../spec_helper'
-require_relative 'fixtures/defined'
+require File.expand_path('../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/defined', __FILE__)
describe "The defined? keyword for literals" do
it "returns 'self' for self" do
@@ -30,12 +30,12 @@ describe "The defined? keyword for literals" do
end
it "returns nil if one element is not defined" do
- ret = defined?([NonExistentConstant, Array])
+ ret = defined?([NonExistantConstant, Array])
ret.should == nil
end
it "returns nil if all elements are not defined" do
- ret = defined?([NonExistentConstant, AnotherNonExistentConstant])
+ ret = defined?([NonExistantConstant, AnotherNonExistantConstant])
ret.should == nil
end
@@ -505,10 +505,6 @@ describe "The defined? keyword for variables" do
DefinedSpecs::Basic.new.global_variable_read.should be_nil
end
- it "returns 'global-variable' for a global variable that has been assigned nil" do
- DefinedSpecs::Basic.new.global_variable_defined_as_nil.should == "global-variable"
- end
-
# MRI appears to special case defined? for $! and $~ in that it returns
# 'global-variable' even when they are not set (or they are always "set"
# but the value may be nil). In other words, 'defined?($~)' will return
@@ -547,12 +543,16 @@ describe "The defined? keyword for variables" do
defined?($+).should be_nil
end
- it "returns nil for any last match global" do
+ it "returns nil for $1-$9" do
defined?($1).should be_nil
+ defined?($2).should be_nil
+ defined?($3).should be_nil
defined?($4).should be_nil
+ defined?($5).should be_nil
+ defined?($6).should be_nil
defined?($7).should be_nil
- defined?($10).should be_nil
- defined?($200).should be_nil
+ defined?($8).should be_nil
+ defined?($9).should be_nil
end
end
@@ -587,10 +587,13 @@ describe "The defined? keyword for variables" do
end
it "returns nil for non-captures" do
+ defined?($3).should be_nil
defined?($4).should be_nil
+ defined?($5).should be_nil
+ defined?($6).should be_nil
defined?($7).should be_nil
- defined?($10).should be_nil
- defined?($200).should be_nil
+ defined?($8).should be_nil
+ defined?($9).should be_nil
end
end
@@ -619,12 +622,16 @@ describe "The defined? keyword for variables" do
defined?($+).should be_nil
end
- it "returns nil for any last match global" do
+ it "returns nil for $1-$9" do
defined?($1).should be_nil
+ defined?($2).should be_nil
+ defined?($3).should be_nil
defined?($4).should be_nil
+ defined?($5).should be_nil
+ defined?($6).should be_nil
defined?($7).should be_nil
- defined?($10).should be_nil
- defined?($200).should be_nil
+ defined?($8).should be_nil
+ defined?($9).should be_nil
end
end
@@ -659,10 +666,13 @@ describe "The defined? keyword for variables" do
end
it "returns nil for non-captures" do
+ defined?($3).should be_nil
defined?($4).should be_nil
+ defined?($5).should be_nil
+ defined?($6).should be_nil
defined?($7).should be_nil
- defined?($10).should be_nil
- defined?($200).should be_nil
+ defined?($8).should be_nil
+ defined?($9).should be_nil
end
end
it "returns 'global-variable' for a global variable that has been assigned" do
diff --git a/spec/ruby/language/encoding_spec.rb b/spec/ruby/language/encoding_spec.rb
index 5430c9cb98..070fa52bba 100644
--- a/spec/ruby/language/encoding_spec.rb
+++ b/spec/ruby/language/encoding_spec.rb
@@ -1,7 +1,7 @@
# -*- encoding: us-ascii -*-
-require_relative '../spec_helper'
-require_relative 'fixtures/coding_us_ascii'
-require_relative 'fixtures/coding_utf_8'
+require File.expand_path('../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/coding_us_ascii', __FILE__)
+require File.expand_path('../fixtures/coding_utf_8', __FILE__)
describe "The __ENCODING__ pseudo-variable" do
it "is an instance of Encoding" do
@@ -14,14 +14,14 @@ describe "The __ENCODING__ pseudo-variable" do
it "is the evaluated strings's one inside an eval" do
eval("__ENCODING__".force_encoding("US-ASCII")).should == Encoding::US_ASCII
- eval("__ENCODING__".force_encoding("BINARY")).should == Encoding::BINARY
+ eval("__ENCODING__".force_encoding("ASCII-8BIT")).should == Encoding::ASCII_8BIT
end
it "is the encoding specified by a magic comment inside an eval" do
- code = "# encoding: BINARY\n__ENCODING__".force_encoding("US-ASCII")
- eval(code).should == Encoding::BINARY
+ code = "# encoding: ASCII-8BIT\n__ENCODING__".force_encoding("US-ASCII")
+ eval(code).should == Encoding::ASCII_8BIT
- code = "# encoding: us-ascii\n__ENCODING__".force_encoding("BINARY")
+ code = "# encoding: us-ascii\n__ENCODING__".force_encoding("ASCII-8BIT")
eval(code).should == Encoding::US_ASCII
end
@@ -31,6 +31,6 @@ describe "The __ENCODING__ pseudo-variable" do
end
it "raises a SyntaxError if assigned to" do
- -> { eval("__ENCODING__ = 1") }.should raise_error(SyntaxError)
+ lambda { eval("__ENCODING__ = 1") }.should raise_error(SyntaxError)
end
end
diff --git a/spec/ruby/language/ensure_spec.rb b/spec/ruby/language/ensure_spec.rb
index a930bda36b..1d99dcf5f2 100644
--- a/spec/ruby/language/ensure_spec.rb
+++ b/spec/ruby/language/ensure_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../spec_helper'
-require_relative 'fixtures/ensure'
+require File.expand_path('../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/ensure', __FILE__)
describe "An ensure block inside a begin block" do
before :each do
@@ -7,7 +7,7 @@ describe "An ensure block inside a begin block" do
end
it "is executed when an exception is raised in it's corresponding begin block" do
- -> {
+ lambda {
begin
ScratchPad << :begin
raise EnsureSpec::Error
@@ -66,18 +66,6 @@ describe "An ensure block inside a begin block" do
:ensure
end.should == :begin
end
-
- it "sets exception cause if raises exception in block and in ensure" do
- -> {
- begin
- raise "from block"
- ensure
- raise "from ensure"
- end
- }.should raise_error(RuntimeError, "from ensure") do |e|
- e.cause.message.should == "from block"
- end
- end
end
describe "The value of an ensure expression," do
@@ -108,7 +96,7 @@ describe "An ensure block inside a method" do
end
it "is executed when an exception is raised in the method" do
- -> { @obj.raise_in_method_with_ensure }.should raise_error(EnsureSpec::Error)
+ lambda { @obj.raise_in_method_with_ensure }.should raise_error(EnsureSpec::Error)
@obj.executed.should == [:method, :ensure]
end
@@ -129,34 +117,6 @@ describe "An ensure block inside a method" do
it "has an impact on the method's explicit return value" do
@obj.explicit_return_in_method_with_ensure.should == :ensure
end
-
- it "has an impact on the method's explicit return value from rescue if returns explicitly" do
- @obj.explicit_return_in_rescue_and_explicit_return_in_ensure.should == "returned in ensure"
- end
-
- it "has no impact on the method's explicit return value from rescue if returns implicitly" do
- @obj.explicit_return_in_rescue_and_implicit_return_in_ensure.should == "returned in rescue"
- end
-
- it "suppresses exception raised in method if returns value explicitly" do
- @obj.raise_and_explicit_return_in_ensure.should == "returned in ensure"
- end
-
- it "suppresses exception raised in rescue if returns value explicitly" do
- @obj.raise_in_rescue_and_explicit_return_in_ensure.should == "returned in ensure"
- end
-
- it "overrides exception raised in rescue if raises exception itself" do
- -> {
- @obj.raise_in_rescue_and_raise_in_ensure
- }.should raise_error(RuntimeError, "raised in ensure")
- end
-
- it "suppresses exception raised in method if raises exception itself" do
- -> {
- @obj.raise_in_method_and_raise_in_ensure
- }.should raise_error(RuntimeError, "raised in ensure")
- end
end
describe "An ensure block inside a class" do
@@ -165,7 +125,7 @@ describe "An ensure block inside a class" do
end
it "is executed when an exception is raised" do
- -> {
+ lambda {
eval <<-ruby
class EnsureInClassExample
ScratchPad << :class
@@ -240,7 +200,7 @@ end
describe "An ensure block inside {} block" do
it "is not allowed" do
- -> {
+ lambda {
eval <<-ruby
lambda {
raise
@@ -258,7 +218,7 @@ ruby_version_is "2.5" do
end
it "is executed when an exception is raised in it's corresponding begin block" do
- -> {
+ lambda {
eval(<<-ruby).call
lambda do
ScratchPad << :begin
diff --git a/spec/ruby/language/execution_spec.rb b/spec/ruby/language/execution_spec.rb
index 4e0310946d..3e6e7ff48c 100644
--- a/spec/ruby/language/execution_spec.rb
+++ b/spec/ruby/language/execution_spec.rb
@@ -1,4 +1,4 @@
-require_relative '../spec_helper'
+require File.expand_path('../../spec_helper', __FILE__)
describe "``" do
it "returns the output of the executed sub-process" do
diff --git a/spec/ruby/language/file_spec.rb b/spec/ruby/language/file_spec.rb
index 729dee1008..409400ca83 100644
--- a/spec/ruby/language/file_spec.rb
+++ b/spec/ruby/language/file_spec.rb
@@ -1,10 +1,10 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/code_loading'
-require_relative 'shared/__FILE__'
+require File.expand_path('../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/code_loading', __FILE__)
+require File.expand_path('../shared/__FILE__', __FILE__)
describe "The __FILE__ pseudo-variable" do
it "raises a SyntaxError if assigned to" do
- -> { eval("__FILE__ = 1") }.should raise_error(SyntaxError)
+ lambda { eval("__FILE__ = 1") }.should raise_error(SyntaxError)
end
it "equals (eval) inside an eval" do
diff --git a/spec/ruby/language/fixtures/array.rb b/spec/ruby/language/fixtures/array.rb
index c1036575ff..4d8ce74ed6 100644
--- a/spec/ruby/language/fixtures/array.rb
+++ b/spec/ruby/language/fixtures/array.rb
@@ -8,25 +8,4 @@ module ArraySpec
[a, b, c, d]
end
end
-
- class SideEffect
- def initialize()
- @call_count = 0
- end
-
- attr_reader :call_count
-
- def array_result(a_number)
- [result(a_number), result(a_number)]
- end
-
- def result(a_number)
- @call_count += 1
- if a_number
- 1
- else
- :thing
- end
- end
- end
end
diff --git a/spec/ruby/language/fixtures/block.rb b/spec/ruby/language/fixtures/block.rb
index 33baac6aeb..9848d18776 100644
--- a/spec/ruby/language/fixtures/block.rb
+++ b/spec/ruby/language/fixtures/block.rb
@@ -15,10 +15,6 @@ module BlockSpecs
def r(a)
yield(*a)
end
-
- def k(*a)
- yield(*a, b: true)
- end
end
# TODO: rewrite all specs that use Yield to use Yielder
diff --git a/spec/ruby/language/fixtures/break.rb b/spec/ruby/language/fixtures/break.rb
index 217c20a2c0..2d07cc3d48 100644
--- a/spec/ruby/language/fixtures/break.rb
+++ b/spec/ruby/language/fixtures/break.rb
@@ -163,7 +163,7 @@ module BreakSpecs
# on the call stack when the lambda is invoked.
def break_in_defining_scope(value=true)
note :a
- note -> {
+ note lambda {
note :b
if value
break :break
@@ -177,7 +177,7 @@ module BreakSpecs
def break_in_nested_scope
note :a
- l = -> do
+ l = lambda do
note :b
break :break
note :c
@@ -197,7 +197,7 @@ module BreakSpecs
def break_in_nested_scope_yield
note :a
- l = -> do
+ l = lambda do
note :b
break :break
note :c
@@ -217,7 +217,7 @@ module BreakSpecs
def break_in_nested_scope_block
note :a
- l = -> do
+ l = lambda do
note :b
break :break
note :c
@@ -251,7 +251,7 @@ module BreakSpecs
# active on the call stack when the lambda is invoked.
def create_lambda
note :la
- l = -> do
+ l = lambda do
note :lb
break :break
note :lc
diff --git a/spec/ruby/language/fixtures/break_lambda_toplevel.rb b/spec/ruby/language/fixtures/break_lambda_toplevel.rb
index da5abbaf00..05af1d3fdc 100644
--- a/spec/ruby/language/fixtures/break_lambda_toplevel.rb
+++ b/spec/ruby/language/fixtures/break_lambda_toplevel.rb
@@ -1,6 +1,6 @@
print "a,"
-print -> {
+print lambda {
print "b,"
break "break,"
print "c,"
diff --git a/spec/ruby/language/fixtures/break_lambda_toplevel_block.rb b/spec/ruby/language/fixtures/break_lambda_toplevel_block.rb
index 3dcee62424..a35cb8a8a1 100644
--- a/spec/ruby/language/fixtures/break_lambda_toplevel_block.rb
+++ b/spec/ruby/language/fixtures/break_lambda_toplevel_block.rb
@@ -1,6 +1,6 @@
print "a,"
-l = -> {
+l = lambda {
print "b,"
break "break,"
print "c,"
diff --git a/spec/ruby/language/fixtures/break_lambda_toplevel_method.rb b/spec/ruby/language/fixtures/break_lambda_toplevel_method.rb
index a5936a3d70..200040d614 100644
--- a/spec/ruby/language/fixtures/break_lambda_toplevel_method.rb
+++ b/spec/ruby/language/fixtures/break_lambda_toplevel_method.rb
@@ -1,6 +1,6 @@
print "a,"
-l = -> {
+l = lambda {
print "b,"
break "break,"
print "c,"
diff --git a/spec/ruby/language/fixtures/bytes_magic_comment.rb b/spec/ruby/language/fixtures/bytes_magic_comment.rb
deleted file mode 100644
index 2bc2bcfb07..0000000000
--- a/spec/ruby/language/fixtures/bytes_magic_comment.rb
+++ /dev/null
@@ -1,2 +0,0 @@
-# encoding: big5
-$magic_comment_result = '§A¦n'.bytes.inspect
diff --git a/spec/ruby/language/fixtures/case_magic_comment.rb b/spec/ruby/language/fixtures/case_magic_comment.rb
deleted file mode 100644
index 96f35a7c94..0000000000
--- a/spec/ruby/language/fixtures/case_magic_comment.rb
+++ /dev/null
@@ -1,2 +0,0 @@
-# CoDiNg: bIg5
-$magic_comment_result = __ENCODING__.name
diff --git a/spec/ruby/language/fixtures/def.rb b/spec/ruby/language/fixtures/def.rb
index e07060ed74..81bfce73d0 100644
--- a/spec/ruby/language/fixtures/def.rb
+++ b/spec/ruby/language/fixtures/def.rb
@@ -1,9 +1,3 @@
-def toplevel_define_other_method
- def nested_method_in_toplevel_method
- 42
- end
-end
-
def some_toplevel_method
end
diff --git a/spec/ruby/language/fixtures/defined.rb b/spec/ruby/language/fixtures/defined.rb
index 8b6004c19f..d26e553c4b 100644
--- a/spec/ruby/language/fixtures/defined.rb
+++ b/spec/ruby/language/fixtures/defined.rb
@@ -94,11 +94,6 @@ module DefinedSpecs
defined? $defined_specs_global_variable_defined
end
- def global_variable_defined_as_nil
- $defined_specs_global_variable_defined_as_nil = nil
- defined? $defined_specs_global_variable_defined_as_nil
- end
-
def class_variable_undefined
defined? @@class_variable_undefined
end
diff --git a/spec/ruby/language/fixtures/emacs_magic_comment.rb b/spec/ruby/language/fixtures/emacs_magic_comment.rb
deleted file mode 100644
index 2b09f3e74c..0000000000
--- a/spec/ruby/language/fixtures/emacs_magic_comment.rb
+++ /dev/null
@@ -1,2 +0,0 @@
-# -*- encoding: big5 -*-
-$magic_comment_result = __ENCODING__.name
diff --git a/spec/ruby/language/fixtures/ensure.rb b/spec/ruby/language/fixtures/ensure.rb
index 6047ac5bc0..d1a9da37b8 100644
--- a/spec/ruby/language/fixtures/ensure.rb
+++ b/spec/ruby/language/fixtures/ensure.rb
@@ -40,50 +40,6 @@ module EnsureSpec
ensure
return :ensure
end
-
- def explicit_return_in_rescue_and_explicit_return_in_ensure
- raise
- rescue
- return 2
- ensure
- return "returned in ensure"
- end
-
- def explicit_return_in_rescue_and_implicit_return_in_ensure
- raise
- rescue
- return "returned in rescue"
- ensure
- 3
- end
-
- def raise_and_explicit_return_in_ensure
- raise
- ensure
- return "returned in ensure"
- end
-
- def raise_in_rescue_and_explicit_return_in_ensure
- raise
- rescue
- raise
- ensure
- return "returned in ensure"
- end
-
- def raise_in_rescue_and_raise_in_ensure
- raise
- rescue
- raise "raised in rescue"
- ensure
- raise "raised in ensure"
- end
-
- def raise_in_method_and_raise_in_ensure
- raise
- ensure
- raise "raised in ensure"
- end
end
end
diff --git a/spec/ruby/language/fixtures/for_scope.rb b/spec/ruby/language/fixtures/for_scope.rb
deleted file mode 100644
index 9c44a23a2c..0000000000
--- a/spec/ruby/language/fixtures/for_scope.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-module ForSpecs
- class ForInClassMethod
- m = :same_variable_set_outside
-
- def self.foo
- all = []
- for m in [:bar, :baz]
- all << m
- end
- all
- end
-
- READER = -> { m }
- end
-end
diff --git a/spec/ruby/language/fixtures/hash_strings_binary.rb b/spec/ruby/language/fixtures/hash_strings_ascii8bit.rb
index 44b99cbf80..4ac11b9930 100644
--- a/spec/ruby/language/fixtures/hash_strings_binary.rb
+++ b/spec/ruby/language/fixtures/hash_strings_ascii8bit.rb
@@ -1,6 +1,6 @@
-# encoding: binary
+# encoding: ascii-8bit
-module HashStringsBinary
+module HashStringsASCII8BIT
def self.literal_hash
{"foo" => "bar"}
end
diff --git a/spec/ruby/language/fixtures/magic_comment.rb b/spec/ruby/language/fixtures/magic_comment.rb
deleted file mode 100644
index 120ef6ff4a..0000000000
--- a/spec/ruby/language/fixtures/magic_comment.rb
+++ /dev/null
@@ -1,2 +0,0 @@
-# encoding: big5
-$magic_comment_result = __ENCODING__.name
diff --git a/spec/ruby/language/fixtures/metaclass.rb b/spec/ruby/language/fixtures/metaclass.rb
index a8f837e701..a1990b9225 100644
--- a/spec/ruby/language/fixtures/metaclass.rb
+++ b/spec/ruby/language/fixtures/metaclass.rb
@@ -31,3 +31,4 @@ module MetaClassSpecs
class D < C; end
end
+
diff --git a/spec/ruby/language/fixtures/no_magic_comment.rb b/spec/ruby/language/fixtures/no_magic_comment.rb
deleted file mode 100644
index 743a0f9503..0000000000
--- a/spec/ruby/language/fixtures/no_magic_comment.rb
+++ /dev/null
@@ -1 +0,0 @@
-$magic_comment_result = __ENCODING__.name
diff --git a/spec/ruby/language/fixtures/print_magic_comment_result_at_exit.rb b/spec/ruby/language/fixtures/print_magic_comment_result_at_exit.rb
deleted file mode 100644
index aa82cf4471..0000000000
--- a/spec/ruby/language/fixtures/print_magic_comment_result_at_exit.rb
+++ /dev/null
@@ -1,3 +0,0 @@
-at_exit {
- print $magic_comment_result
-}
diff --git a/spec/ruby/language/fixtures/rescue.rb b/spec/ruby/language/fixtures/rescue.rb
index b906e17a2f..3fa5df1eb5 100644
--- a/spec/ruby/language/fixtures/rescue.rb
+++ b/spec/ruby/language/fixtures/rescue.rb
@@ -60,8 +60,4 @@ module RescueSpecs
ScratchPad << :outside_begin
:return_val
end
-
- def self.raise_standard_error
- raise StandardError, "an error occurred"
- end
end
diff --git a/spec/ruby/language/fixtures/second_line_magic_comment.rb b/spec/ruby/language/fixtures/second_line_magic_comment.rb
deleted file mode 100644
index a3dd50393b..0000000000
--- a/spec/ruby/language/fixtures/second_line_magic_comment.rb
+++ /dev/null
@@ -1,3 +0,0 @@
-
-# encoding: big5
-$magic_comment_result = __ENCODING__.name
diff --git a/spec/ruby/language/fixtures/second_token_magic_comment.rb b/spec/ruby/language/fixtures/second_token_magic_comment.rb
deleted file mode 100644
index 8d443e68f3..0000000000
--- a/spec/ruby/language/fixtures/second_token_magic_comment.rb
+++ /dev/null
@@ -1,2 +0,0 @@
-1 + 1 # encoding: big5
-$magic_comment_result = __ENCODING__.name
diff --git a/spec/ruby/language/fixtures/send.rb b/spec/ruby/language/fixtures/send.rb
index 918241e171..c3013616b2 100644
--- a/spec/ruby/language/fixtures/send.rb
+++ b/spec/ruby/language/fixtures/send.rb
@@ -53,9 +53,8 @@ module LangSendSpecs
end
class PrivateGetter
- attr_accessor :foo
+ attr_reader :foo
private :foo
- private :foo=
def call_self_foo
self.foo
diff --git a/spec/ruby/language/fixtures/shebang_magic_comment.rb b/spec/ruby/language/fixtures/shebang_magic_comment.rb
deleted file mode 100755
index f8e5e7d8e4..0000000000
--- a/spec/ruby/language/fixtures/shebang_magic_comment.rb
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/usr/bin/ruby
-# encoding: big5
-$magic_comment_result = __ENCODING__.name
diff --git a/spec/ruby/language/fixtures/super.rb b/spec/ruby/language/fixtures/super.rb
index 6a024cae23..09a454bdf4 100644
--- a/spec/ruby/language/fixtures/super.rb
+++ b/spec/ruby/language/fixtures/super.rb
@@ -1,4 +1,4 @@
-module SuperSpecs
+module Super
module S1
class A
def foo(a)
@@ -282,7 +282,7 @@ module SuperSpecs
#
# When name3 is called then, Alias2 (NOT Alias3) is presented as the
# current module to Alias2#name, so that when super is called,
- # Alias2's superclass is next.
+ # Alias2->superclass is next.
#
# Otherwise, Alias2 is next, which is where name was to begin with,
# causing the wrong #name method to be called.
@@ -377,12 +377,12 @@ module SuperSpecs
end
def b
- block_ref = -> { 15 }
+ block_ref = lambda { 15 }
[super { 14 }, super(&block_ref)]
end
def c
- block_ref = -> { 16 }
+ block_ref = lambda { 16 }
super(&block_ref)
end
end
@@ -455,38 +455,6 @@ module SuperSpecs
end
end
- module ZSuperWithRestReassigned
- class A
- def a(*args)
- args
- end
- end
-
- class B < A
- def a(*args)
- args = ["foo"]
-
- super
- end
- end
- end
-
- module ZSuperWithRestReassignedWithScalar
- class A
- def a(*args)
- args
- end
- end
-
- class B < A
- def a(*args)
- args = "foo"
-
- super
- end
- end
- end
-
module ZSuperWithUnderscores
class A
def m(*args)
diff --git a/spec/ruby/language/fixtures/utf16-be-nobom.rb b/spec/ruby/language/fixtures/utf16-be-nobom.rb
deleted file mode 100644
index 99e2ce8ce8..0000000000
--- a/spec/ruby/language/fixtures/utf16-be-nobom.rb
+++ /dev/null
Binary files differ
diff --git a/spec/ruby/language/fixtures/utf16-le-nobom.rb b/spec/ruby/language/fixtures/utf16-le-nobom.rb
deleted file mode 100644
index 98de9697ca..0000000000
--- a/spec/ruby/language/fixtures/utf16-le-nobom.rb
+++ /dev/null
Binary files differ
diff --git a/spec/ruby/language/fixtures/utf8-bom.rb b/spec/ruby/language/fixtures/utf8-bom.rb
deleted file mode 100644
index 50c223a922..0000000000
--- a/spec/ruby/language/fixtures/utf8-bom.rb
+++ /dev/null
@@ -1,2 +0,0 @@
-# encoding: utf-8
-puts 'hello'
diff --git a/spec/ruby/language/fixtures/utf8-nobom.rb b/spec/ruby/language/fixtures/utf8-nobom.rb
deleted file mode 100644
index 75f5563b95..0000000000
--- a/spec/ruby/language/fixtures/utf8-nobom.rb
+++ /dev/null
@@ -1,2 +0,0 @@
-# encoding: utf-8
-puts 'hello'
diff --git a/spec/ruby/language/fixtures/vim_magic_comment.rb b/spec/ruby/language/fixtures/vim_magic_comment.rb
deleted file mode 100644
index 60cbe7a3bf..0000000000
--- a/spec/ruby/language/fixtures/vim_magic_comment.rb
+++ /dev/null
@@ -1,2 +0,0 @@
-# vim: filetype=ruby, fileencoding=big5, tabsize=3, shiftwidth=3
-$magic_comment_result = __ENCODING__.name
diff --git a/spec/ruby/language/fixtures/yield.rb b/spec/ruby/language/fixtures/yield.rb
index 9f7a2ba238..a195616640 100644
--- a/spec/ruby/language/fixtures/yield.rb
+++ b/spec/ruby/language/fixtures/yield.rb
@@ -21,10 +21,6 @@ module YieldSpecs
yield(*a)
end
- def k(a)
- yield(*a, b: true)
- end
-
def rs(a, b, c)
yield(a, b, *c)
end
diff --git a/spec/ruby/language/for_spec.rb b/spec/ruby/language/for_spec.rb
index 0ad5ea88af..c9d043fa25 100644
--- a/spec/ruby/language/for_spec.rb
+++ b/spec/ruby/language/for_spec.rb
@@ -1,5 +1,4 @@
-require_relative '../spec_helper'
-require_relative 'fixtures/for_scope'
+require File.expand_path('../../spec_helper', __FILE__)
# for name[, name]... in expr [do]
# body
@@ -33,13 +32,14 @@ describe "The for expression" do
end
it "iterates over any object responding to 'each'" do
- obj = Object.new
- def obj.each
- (0..10).each { |i| yield i }
+ class XYZ
+ def each
+ (0..10).each { |i| yield i }
+ end
end
j = 0
- for i in obj
+ for i in XYZ.new
j += i
end
j.should == 55
@@ -131,11 +131,6 @@ describe "The for expression" do
a.should == 123
end
- it "does not try to access variables outside the method" do
- ForSpecs::ForInClassMethod.foo.should == [:bar, :baz]
- ForSpecs::ForInClassMethod::READER.call.should == :same_variable_set_outside
- end
-
it "returns expr" do
for i in 1..3; end.should == (1..3)
for i,j in { 1 => 10, 2 => 20 }; end.should == { 1 => 10, 2 => 20 }
diff --git a/spec/ruby/language/hash_spec.rb b/spec/ruby/language/hash_spec.rb
index 6f2e8e5cf0..edd9d4fbb2 100644
--- a/spec/ruby/language/hash_spec.rb
+++ b/spec/ruby/language/hash_spec.rb
@@ -1,7 +1,7 @@
-require_relative '../spec_helper'
-require_relative 'fixtures/hash_strings_binary'
-require_relative 'fixtures/hash_strings_utf8'
-require_relative 'fixtures/hash_strings_usascii'
+require File.expand_path('../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/hash_strings_ascii8bit', __FILE__)
+require File.expand_path('../fixtures/hash_strings_utf8', __FILE__)
+require File.expand_path('../fixtures/hash_strings_usascii', __FILE__)
describe "Hash literal" do
it "{} should return an empty hash" do
@@ -63,7 +63,7 @@ describe "Hash literal" do
end
it "with '==>' in the middle raises SyntaxError" do
- -> { eval("{:a ==> 1}") }.should raise_error(SyntaxError)
+ lambda { eval("{:a ==> 1}") }.should raise_error(SyntaxError)
end
it "constructs a new hash with the given elements" do
@@ -128,34 +128,25 @@ describe "Hash literal" do
{a: 1, **obj, c: 3}.should == {a:1, b: 2, c: 3, d: 4}
end
- ruby_version_is ""..."2.7" do
- it "raises a TypeError if any splatted elements keys are not symbols" do
- h = {1 => 2, b: 3}
- -> { {a: 1, **h} }.should raise_error(TypeError)
- end
- end
-
- ruby_version_is "2.7" do
- it "allows splatted elements keys that are not symbols" do
- h = {1 => 2, b: 3}
- {a: 1, **h}.should == {a: 1, 1 => 2, b: 3}
- end
+ it "raises a TypeError if any splatted elements keys are not symbols" do
+ h = {1 => 2, b: 3}
+ lambda { {a: 1, **h} }.should raise_error(TypeError)
end
it "raises a TypeError if #to_hash does not return a Hash" do
obj = mock("hash splat")
obj.should_receive(:to_hash).and_return(obj)
- -> { {**obj} }.should raise_error(TypeError)
+ lambda { {**obj} }.should raise_error(TypeError)
end
it "does not change encoding of literal string keys during creation" do
- binary_hash = HashStringsBinary.literal_hash
+ ascii8bit_hash = HashStringsASCII8BIT.literal_hash
utf8_hash = HashStringsUTF8.literal_hash
usascii_hash = HashStringsUSASCII.literal_hash
- binary_hash.keys.first.encoding.should == Encoding::BINARY
- binary_hash.keys.first.should == utf8_hash.keys.first
+ ascii8bit_hash.keys.first.encoding.should == Encoding::ASCII_8BIT
+ ascii8bit_hash.keys.first.should == utf8_hash.keys.first
utf8_hash.keys.first.encoding.should == Encoding::UTF_8
utf8_hash.keys.first.should == usascii_hash.keys.first
usascii_hash.keys.first.encoding.should == Encoding::US_ASCII
diff --git a/spec/ruby/language/heredoc_spec.rb b/spec/ruby/language/heredoc_spec.rb
index e7655a9216..a57a7b0bb9 100644
--- a/spec/ruby/language/heredoc_spec.rb
+++ b/spec/ruby/language/heredoc_spec.rb
@@ -1,6 +1,6 @@
# -*- encoding: us-ascii -*-
-require_relative '../spec_helper'
+require File.expand_path('../../spec_helper', __FILE__)
describe "Heredoc string" do
@@ -13,7 +13,6 @@ describe "Heredoc string" do
foo bar#{@ip}
HERE
s.should == "foo barxxx\n"
- s.encoding.should == Encoding::US_ASCII
end
it 'allow HEREDOC with <<"identifier", interpolated' do
@@ -21,7 +20,6 @@ HERE
foo bar#{@ip}
HERE
s.should == "foo barxxx\n"
- s.encoding.should == Encoding::US_ASCII
end
it "allows HEREDOC with <<'identifier', no interpolation" do
@@ -29,7 +27,6 @@ HERE
foo bar#{@ip}
HERE
s.should == 'foo bar#{@ip}' + "\n"
- s.encoding.should == Encoding::US_ASCII
end
it "allows HEREDOC with <<-identifier, allowing to indent identifier, interpolated" do
@@ -38,7 +35,6 @@ HERE
HERE
s.should == " foo barxxx\n"
- s.encoding.should == Encoding::US_ASCII
end
it 'allows HEREDOC with <<-"identifier", allowing to indent identifier, interpolated' do
@@ -47,7 +43,6 @@ HERE
HERE
s.should == " foo barxxx\n"
- s.encoding.should == Encoding::US_ASCII
end
it "allows HEREDOC with <<-'identifier', allowing to indent identifier, no interpolation" do
@@ -56,36 +51,37 @@ HERE
HERE
s.should == ' foo bar#{@ip}' + "\n"
- s.encoding.should == Encoding::US_ASCII
end
- it "allows HEREDOC with <<~'identifier', allowing to indent identifier and content" do
- require_relative 'fixtures/squiggly_heredoc'
- SquigglyHeredocSpecs.message.should == "character density, n.:\n The number of very weird people in the office.\n"
- end
-
- it "trims trailing newline character for blank HEREDOC with <<~'identifier'" do
- require_relative 'fixtures/squiggly_heredoc'
- SquigglyHeredocSpecs.blank.should == ""
- end
-
- it 'allows HEREDOC with <<~identifier, interpolated' do
- require_relative 'fixtures/squiggly_heredoc'
- SquigglyHeredocSpecs.unquoted.should == "unquoted interpolated\n"
- end
-
- it 'allows HEREDOC with <<~"identifier", interpolated' do
- require_relative 'fixtures/squiggly_heredoc'
- SquigglyHeredocSpecs.doublequoted.should == "doublequoted interpolated\n"
- end
-
- it "allows HEREDOC with <<~'identifier', no interpolation" do
- require_relative 'fixtures/squiggly_heredoc'
- SquigglyHeredocSpecs.singlequoted.should == "singlequoted \#{\"interpolated\"}\n"
- end
-
- it "selects the least-indented line and removes its indentation from all the lines" do
- require_relative 'fixtures/squiggly_heredoc'
- SquigglyHeredocSpecs.least_indented_on_the_last_line.should == " a\n b\nc\n"
+ ruby_version_is "2.3" do
+ it "allows HEREDOC with <<~'identifier', allowing to indent identifier and content" do
+ require File.expand_path('../fixtures/squiggly_heredoc', __FILE__)
+ SquigglyHeredocSpecs.message.should == "character density, n.:\n The number of very weird people in the office.\n"
+ end
+
+ it "trims trailing newline character for blank HEREDOC with <<~'identifier'" do
+ require File.expand_path('../fixtures/squiggly_heredoc', __FILE__)
+ SquigglyHeredocSpecs.blank.should == ""
+ end
+
+ it 'allows HEREDOC with <<~identifier, interpolated' do
+ require File.expand_path('../fixtures/squiggly_heredoc', __FILE__)
+ SquigglyHeredocSpecs.unquoted.should == "unquoted interpolated\n"
+ end
+
+ it 'allows HEREDOC with <<~"identifier", interpolated' do
+ require File.expand_path('../fixtures/squiggly_heredoc', __FILE__)
+ SquigglyHeredocSpecs.doublequoted.should == "doublequoted interpolated\n"
+ end
+
+ it "allows HEREDOC with <<~'identifier', no interpolation" do
+ require File.expand_path('../fixtures/squiggly_heredoc', __FILE__)
+ SquigglyHeredocSpecs.singlequoted.should == "singlequoted \#{\"interpolated\"}\n"
+ end
+
+ it "selects the least-indented line and removes its indentation from all the lines" do
+ require File.expand_path('../fixtures/squiggly_heredoc', __FILE__)
+ SquigglyHeredocSpecs.least_indented_on_the_last_line.should == " a\n b\nc\n"
+ end
end
end
diff --git a/spec/ruby/language/if_spec.rb b/spec/ruby/language/if_spec.rb
index d1d95c1607..284d852462 100644
--- a/spec/ruby/language/if_spec.rb
+++ b/spec/ruby/language/if_spec.rb
@@ -1,20 +1,22 @@
-require_relative '../spec_helper'
+require File.expand_path('../../spec_helper', __FILE__)
describe "The if expression" do
- describe "accepts multiple assignments in conditional expression" do
- before(:each) { ScratchPad.record([]) }
- after(:each) { ScratchPad.clear }
-
- it 'with non-nil values' do
- ary = [1, 2]
- eval "if (a, b = ary); ScratchPad.record [a, b]; end"
- ScratchPad.recorded.should == [1, 2]
- end
-
- it 'with nil values' do
- ary = nil
- eval "if (a, b = ary); else; ScratchPad.record [a, b]; end"
- ScratchPad.recorded.should == [nil, nil]
+ ruby_version_is '2.4' do
+ describe "accepts multiple assignments in conditional expression" do
+ before(:each) { ScratchPad.record([]) }
+ after(:each) { ScratchPad.clear }
+
+ it 'with non-nil values' do
+ ary = [1, 2]
+ eval "if (a, b = ary); ScratchPad.record [a, b]; end"
+ ScratchPad.recorded.should == [1, 2]
+ end
+
+ it 'with nil values' do
+ ary = nil
+ eval "if (a, b = ary); else; ScratchPad.record [a, b]; end"
+ ScratchPad.recorded.should == [nil, nil]
+ end
end
end
diff --git a/spec/ruby/language/lambda_spec.rb b/spec/ruby/language/lambda_spec.rb
index ddd0b574b3..43e2d60ae3 100644
--- a/spec/ruby/language/lambda_spec.rb
+++ b/spec/ruby/language/lambda_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../spec_helper'
-require_relative 'fixtures/classes'
+require File.expand_path('../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
describe "A lambda literal -> () { }" do
SpecEvaluate.desc = "for definition"
@@ -7,7 +7,7 @@ describe "A lambda literal -> () { }" do
it "returns a Proc object when used in a BasicObject method" do
klass = Class.new(BasicObject) do
def create_lambda
- -> { }
+ -> () { }
end
end
@@ -15,21 +15,11 @@ describe "A lambda literal -> () { }" do
end
it "does not execute the block" do
- -> { fail }.should be_an_instance_of(Proc)
+ ->() { fail }.should be_an_instance_of(Proc)
end
it "returns a lambda" do
- -> { }.lambda?.should be_true
- end
-
- ruby_version_is "2.6" do
- it "may include a rescue clause" do
- eval('-> do raise ArgumentError; rescue ArgumentError; 7; end').should be_an_instance_of(Proc)
- end
-
- it "may include a ensure clause" do
- eval('-> do 1; ensure; 2; end').should be_an_instance_of(Proc)
- end
+ -> () { }.lambda?.should be_true
end
it "has its own scope for local variables" do
@@ -111,7 +101,7 @@ describe "A lambda literal -> () { }" do
@a = -> (a:) { a }
ruby
- -> { @a.() }.should raise_error(ArgumentError)
+ lambda { @a.() }.should raise_error(ArgumentError)
@a.(a: 1).should == 1
end
@@ -129,7 +119,7 @@ describe "A lambda literal -> () { }" do
@a.().should be_nil
@a.(a: 1, b: 2).should be_nil
- -> { @a.(1) }.should raise_error(ArgumentError)
+ lambda { @a.(1) }.should raise_error(ArgumentError)
end
evaluate <<-ruby do
@@ -153,8 +143,8 @@ describe "A lambda literal -> () { }" do
ruby
@a.(1, 2).should == [1, 2]
- -> { @a.() }.should raise_error(ArgumentError)
- -> { @a.(1) }.should raise_error(ArgumentError)
+ lambda { @a.() }.should raise_error(ArgumentError)
+ lambda { @a.(1) }.should raise_error(ArgumentError)
end
evaluate <<-ruby do
@@ -186,11 +176,9 @@ describe "A lambda literal -> () { }" do
@a.().should == {}
@a.(1, 2, 3, a: 4, b: 5).should == {a: 4, b: 5}
- suppress_keyword_warning do
- h = mock("keyword splat")
- h.should_receive(:to_hash).and_return({a: 1})
- @a.(h).should == {a: 1}
- end
+ h = mock("keyword splat")
+ h.should_receive(:to_hash).and_return({a: 1})
+ @a.(h).should == {a: 1}
end
evaluate <<-ruby do
@@ -267,43 +255,25 @@ describe "A lambda literal -> () { }" do
end
describe "with circular optional argument reference" do
- ruby_version_is ''...'2.7' do
- it "warns and uses a nil value when there is an existing local variable with same name" do
- a = 1
- -> {
- @proc = eval "-> (a=a) { a }"
- }.should complain(/circular argument reference/)
- @proc.call.should == nil
- end
-
- it "warns and uses a nil value when there is an existing method with same name" do
- def a; 1; end
- -> {
- @proc = eval "-> (a=a) { a }"
- }.should complain(/circular argument reference/)
- @proc.call.should == nil
- end
+ it "shadows an existing local with the same name as the argument" do
+ a = 1
+ -> {
+ @proc = eval "-> (a=a) { a }"
+ }.should complain(/circular argument reference/)
+ @proc.call.should == nil
end
- ruby_version_is '2.7' do
- it "raises a SyntaxError if using an existing local with the same name as the argument" do
- a = 1
- -> {
- @proc = eval "-> (a=a) { a }"
- }.should raise_error(SyntaxError)
- end
-
- it "raises a SyntaxError if there is an existing method with the same name as the argument" do
- def a; 1; end
- -> {
- @proc = eval "-> (a=a) { a }"
- }.should raise_error(SyntaxError)
- end
+ it "shadows an existing method with the same name as the argument" do
+ def a; 1; end
+ -> {
+ @proc = eval "-> (a=a) { a }"
+ }.should complain(/circular argument reference/)
+ @proc.call.should == nil
end
it "calls an existing method with the same name as the argument if explicitly using ()" do
def a; 1; end
- -> a=a() { a }.call.should == 1
+ -> (a=a()) { a }.call.should == 1
end
end
end
@@ -335,37 +305,19 @@ describe "A lambda expression 'lambda { ... }'" do
lambda { lambda }.should raise_error(ArgumentError)
end
- ruby_version_is "2.5" do
- it "may include a rescue clause" do
- eval('lambda do raise ArgumentError; rescue ArgumentError; 7; end').should be_an_instance_of(Proc)
- end
- end
-
-
context "with an implicit block" do
before do
def meth; lambda; end
end
- ruby_version_is ""..."2.7" do
- it "can be created" do
- implicit_lambda = nil
- -> {
- implicit_lambda = meth { 1 }
- }.should complain(/tried to create Proc object without a block/)
+ it "can be created" do
+ implicit_lambda = nil
+ -> {
+ implicit_lambda = meth { 1 }
+ }.should complain(/tried to create Proc object without a block/)
- implicit_lambda.lambda?.should be_true
- implicit_lambda.call.should == 1
- end
- end
-
- ruby_version_is "2.7" do
- it "raises ArgumentError" do
- implicit_lambda = nil
- -> {
- meth { 1 }
- }.should raise_error(ArgumentError, /tried to create Proc object without a block/)
- end
+ implicit_lambda.lambda?.should be_true
+ implicit_lambda.call.should == 1
end
end
@@ -540,11 +492,9 @@ describe "A lambda expression 'lambda { ... }'" do
@a.().should == {}
@a.(1, 2, 3, a: 4, b: 5).should == {a: 4, b: 5}
- suppress_keyword_warning do
- h = mock("keyword splat")
- h.should_receive(:to_hash).and_return({a: 1})
- @a.(h).should == {a: 1}
- end
+ h = mock("keyword splat")
+ h.should_receive(:to_hash).and_return({a: 1})
+ @a.(h).should == {a: 1}
end
evaluate <<-ruby do
diff --git a/spec/ruby/language/line_spec.rb b/spec/ruby/language/line_spec.rb
index fcadaa71d7..d9fd307dab 100644
--- a/spec/ruby/language/line_spec.rb
+++ b/spec/ruby/language/line_spec.rb
@@ -1,10 +1,10 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/code_loading'
-require_relative 'shared/__LINE__'
+require File.expand_path('../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/code_loading', __FILE__)
+require File.expand_path('../shared/__LINE__', __FILE__)
describe "The __LINE__ pseudo-variable" do
it "raises a SyntaxError if assigned to" do
- -> { eval("__LINE__ = 1") }.should raise_error(SyntaxError)
+ lambda { eval("__LINE__ = 1") }.should raise_error(SyntaxError)
end
before :each do
diff --git a/spec/ruby/language/loop_spec.rb b/spec/ruby/language/loop_spec.rb
index fd17b53910..4e60e0d8e6 100644
--- a/spec/ruby/language/loop_spec.rb
+++ b/spec/ruby/language/loop_spec.rb
@@ -1,4 +1,4 @@
-require_relative '../spec_helper'
+require File.expand_path('../../spec_helper', __FILE__)
describe "The loop expression" do
it "repeats the given block until a break is called" do
@@ -15,7 +15,7 @@ describe "The loop expression" do
inner_loop = 123
break
end
- -> { inner_loop }.should raise_error(NameError)
+ lambda { inner_loop }.should raise_error(NameError)
end
it "returns the value passed to break if interrupted by break" do
diff --git a/spec/ruby/language/magic_comment_spec.rb b/spec/ruby/language/magic_comment_spec.rb
index f2bf3a08e5..2f6e3b5c3a 100644
--- a/spec/ruby/language/magic_comment_spec.rb
+++ b/spec/ruby/language/magic_comment_spec.rb
@@ -1,92 +1,62 @@
-require_relative '../spec_helper'
+require File.expand_path('../../spec_helper', __FILE__)
-# See core/kernel/eval_spec.rb for more magic comments specs for eval()
-describe :magic_comments, shared: true do
- before :each do
- @default = @method == :locale ? Encoding.find('locale') : Encoding::UTF_8
+describe "Magic comment" do
+ it "is optional" do
+ eval("__ENCODING__").should be_an_instance_of(Encoding)
end
- it "are optional" do
- @object.call('no_magic_comment.rb').should == @default.name
+ it "determines __ENCODING__" do
+ eval(<<EOS.force_encoding("US-ASCII")).should == Encoding::ASCII_8BIT
+# encoding: ASCII-8BIT
+__ENCODING__
+EOS
end
- it "are case-insensitive" do
- @object.call('case_magic_comment.rb').should == Encoding::Big5.name
+ it "is case-insensitive" do
+ eval(<<EOS.force_encoding("US-ASCII")).should == Encoding::ASCII_8BIT
+# CoDiNg: aScIi-8bIt
+__ENCODING__
+EOS
end
it "must be at the first line" do
- @object.call('second_line_magic_comment.rb').should == @default.name
+ eval(<<EOS.force_encoding("US-ASCII")).should == Encoding::US_ASCII
+
+# encoding: ASCII-8BIT
+__ENCODING__
+EOS
end
it "must be the first token of the line" do
- @object.call('second_token_magic_comment.rb').should == @default.name
+ eval(<<EOS.force_encoding("US-ASCII")).should == Encoding::US_ASCII
+1+1 # encoding: ASCII-8BIT
+__ENCODING__
+EOS
+ eval(<<EOS.force_encoding("US-ASCII")).should == Encoding::ASCII_8BIT
+ # encoding: ASCII-8BIT
+__ENCODING__
+EOS
end
it "can be after the shebang" do
- @object.call('shebang_magic_comment.rb').should == Encoding::Big5.name
+ eval(<<EOS.force_encoding("US-ASCII")).should == Encoding::ASCII_8BIT
+#!/usr/bin/ruby -Ku
+# encoding: ASCII-8BIT
+__ENCODING__
+EOS
end
it "can take Emacs style" do
- @object.call('emacs_magic_comment.rb').should == Encoding::Big5.name
+ eval(<<EOS.force_encoding("US-ASCII")).should == Encoding::ASCII_8BIT
+# -*- encoding: ascii-8bit -*-
+__ENCODING__
+EOS
end
it "can take vim style" do
- @object.call('vim_magic_comment.rb').should == Encoding::Big5.name
- end
-
- it "determine __ENCODING__" do
- @object.call('magic_comment.rb').should == Encoding::Big5.name
- end
-
- it "do not cause bytes to be mangled by passing them through the wrong encoding" do
- @object.call('bytes_magic_comment.rb').should == [167, 65, 166, 110].inspect
- end
-end
-
-describe "Magic comments" do
- describe "in stdin" do
- it_behaves_like :magic_comments, :locale, -> file {
- print_at_exit = fixture(__FILE__, "print_magic_comment_result_at_exit.rb")
- ruby_exe(nil, args: "< #{fixture(__FILE__, file)}", options: "-r#{print_at_exit}")
- }
- end
-
- platform_is_not :windows do
- describe "in an -e argument" do
- it_behaves_like :magic_comments, :locale, -> file {
- print_at_exit = fixture(__FILE__, "print_magic_comment_result_at_exit.rb")
- # Use UTF-8, as it is the default source encoding for files
- code = File.read(fixture(__FILE__, file), encoding: 'utf-8')
- IO.popen([*ruby_exe, "-r", print_at_exit, "-e", code], &:read)
- }
- end
- end
-
- describe "in the main file" do
- it_behaves_like :magic_comments, :UTF8, -> file {
- print_at_exit = fixture(__FILE__, "print_magic_comment_result_at_exit.rb")
- ruby_exe(fixture(__FILE__, file), options: "-r#{print_at_exit}")
- }
- end
-
- describe "in a loaded file" do
- it_behaves_like :magic_comments, :UTF8, -> file {
- load fixture(__FILE__, file)
- $magic_comment_result
- }
- end
-
- describe "in a required file" do
- it_behaves_like :magic_comments, :UTF8, -> file {
- require fixture(__FILE__, file)
- $magic_comment_result
- }
- end
-
- describe "in an eval" do
- it_behaves_like :magic_comments, :UTF8, -> file {
- # Use UTF-8, as it is the default source encoding for files
- eval(File.read(fixture(__FILE__, file), encoding: 'utf-8'))
- }
+ eval(<<EOS.force_encoding("US-ASCII")).should == Encoding::ASCII_8BIT
+# vim: filetype=ruby, fileencoding=ascii-8bit, tabsize=3, shiftwidth=3
+__ENCODING__
+EOS
end
end
diff --git a/spec/ruby/language/match_spec.rb b/spec/ruby/language/match_spec.rb
index ebf677cabc..81604e94b2 100644
--- a/spec/ruby/language/match_spec.rb
+++ b/spec/ruby/language/match_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../spec_helper'
-require_relative 'fixtures/match_operators'
+require File.expand_path('../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/match_operators', __FILE__)
describe "The !~ operator" do
before :each do
@@ -48,13 +48,6 @@ describe "The =~ operator with named captures" do
end
end
- describe "on syntax of 'string_literal' =~ /regexp/" do
- it "does not set local variables" do
- 'string literal' =~ /(?<matched>str)(?<unmatched>lit)?/
- local_variables.should == []
- end
- end
-
describe "on syntax of string_variable =~ /regexp/" do
it "does not set local variables" do
@string =~ /(?<matched>foo)(?<unmatched>bar)?/
diff --git a/spec/ruby/language/metaclass_spec.rb b/spec/ruby/language/metaclass_spec.rb
index fc83067977..b3bcd9ef18 100644
--- a/spec/ruby/language/metaclass_spec.rb
+++ b/spec/ruby/language/metaclass_spec.rb
@@ -1,6 +1,6 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/class'
-require_relative 'fixtures/metaclass'
+require File.expand_path('../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/class', __FILE__)
+require File.expand_path('../fixtures/metaclass', __FILE__)
describe "self in a metaclass body (class << obj)" do
it "is TrueClass for true" do
@@ -16,11 +16,11 @@ describe "self in a metaclass body (class << obj)" do
end
it "raises a TypeError for numbers" do
- -> { class << 1; self; end }.should raise_error(TypeError)
+ lambda { class << 1; self; end }.should raise_error(TypeError)
end
it "raises a TypeError for symbols" do
- -> { class << :symbol; self; end }.should raise_error(TypeError)
+ lambda { class << :symbol; self; end }.should raise_error(TypeError)
end
it "is a singleton Class instance" do
@@ -64,11 +64,11 @@ describe "A constant on a metaclass" do
class << @object
CONST
end
- -> { CONST }.should raise_error(NameError)
+ lambda { CONST }.should raise_error(NameError)
end
it "cannot be accessed via object::CONST" do
- -> do
+ lambda do
@object::CONST
end.should raise_error(TypeError)
end
@@ -79,7 +79,7 @@ describe "A constant on a metaclass" do
CONST = 100
end
- -> do
+ lambda do
@object::CONST
end.should raise_error(NameError)
end
@@ -96,7 +96,7 @@ describe "A constant on a metaclass" do
it "is not preserved when the object is duped" do
@object = @object.dup
- -> do
+ lambda do
class << @object; CONST; end
end.should raise_error(NameError)
end
diff --git a/spec/ruby/language/method_spec.rb b/spec/ruby/language/method_spec.rb
index 0486025792..ca939dbab6 100644
--- a/spec/ruby/language/method_spec.rb
+++ b/spec/ruby/language/method_spec.rb
@@ -1,4 +1,4 @@
-require_relative '../spec_helper'
+require File.expand_path('../../spec_helper', __FILE__)
describe "A method send" do
evaluate <<-ruby do
@@ -40,7 +40,7 @@ describe "A method send" do
x = mock("splat argument")
x.should_receive(:to_a).and_return(1)
- -> { m(*x) }.should raise_error(TypeError)
+ lambda { m(*x) }.should raise_error(TypeError)
end
end
@@ -74,7 +74,7 @@ describe "A method send" do
x = mock("splat argument")
x.should_receive(:to_a).and_return(1)
- -> { m(*x, 2, 3) }.should raise_error(TypeError)
+ lambda { m(*x, 2, 3) }.should raise_error(TypeError)
end
end
@@ -108,7 +108,7 @@ describe "A method send" do
x = mock("splat argument")
x.should_receive(:to_a).and_return(1)
- -> { m(1, *x, 2, 3) }.should raise_error(TypeError)
+ lambda { m(1, *x, 2, 3) }.should raise_error(TypeError)
end
it "copies the splatted array" do
@@ -153,7 +153,7 @@ describe "A method send" do
x = mock("splat argument")
x.should_receive(:to_a).and_return(1)
- -> { m(1, 2, *x) }.should raise_error(TypeError)
+ lambda { m(1, 2, *x) }.should raise_error(TypeError)
end
end
end
@@ -197,7 +197,7 @@ describe "An element assignment method send" do
x = mock("splat argument")
x.should_receive(:to_a).and_return(1)
- -> { @o[*x] = 1 }.should raise_error(TypeError)
+ lambda { @o[*x] = 1 }.should raise_error(TypeError)
end
end
@@ -235,7 +235,7 @@ describe "An element assignment method send" do
x = mock("splat argument")
x.should_receive(:to_a).and_return(1)
- -> { @o[*x, 2, 3] = 4 }.should raise_error(TypeError)
+ lambda { @o[*x, 2, 3] = 4 }.should raise_error(TypeError)
end
end
@@ -273,7 +273,7 @@ describe "An element assignment method send" do
x = mock("splat argument")
x.should_receive(:to_a).and_return(1)
- -> { @o[1, 2, *x, 3] = 4 }.should raise_error(TypeError)
+ lambda { @o[1, 2, *x, 3] = 4 }.should raise_error(TypeError)
end
end
@@ -311,7 +311,7 @@ describe "An element assignment method send" do
x = mock("splat argument")
x.should_receive(:to_a).and_return(1)
- -> { @o[1, 2, 3, *x] = 4 }.should raise_error(TypeError)
+ lambda { @o[1, 2, 3, *x] = 4 }.should raise_error(TypeError)
end
end
end
@@ -348,7 +348,7 @@ describe "An attribute assignment method send" do
x = mock("splat argument")
x.should_receive(:to_a).and_return(1)
- -> { @o.send :m=, *x, 1 }.should raise_error(TypeError)
+ lambda { @o.send :m=, *x, 1 }.should raise_error(TypeError)
end
end
@@ -383,7 +383,7 @@ describe "An attribute assignment method send" do
x = mock("splat argument")
x.should_receive(:to_a).and_return(1)
- -> { @o.send :m=, *x, 2, 3, 4 }.should raise_error(TypeError)
+ lambda { @o.send :m=, *x, 2, 3, 4 }.should raise_error(TypeError)
end
end
@@ -418,7 +418,7 @@ describe "An attribute assignment method send" do
x = mock("splat argument")
x.should_receive(:to_a).and_return(1)
- -> { @o.send :m=, 1, 2, *x, 3, 4 }.should raise_error(TypeError)
+ lambda { @o.send :m=, 1, 2, *x, 3, 4 }.should raise_error(TypeError)
end
end
@@ -453,7 +453,7 @@ describe "An attribute assignment method send" do
x = mock("splat argument")
x.should_receive(:to_a).and_return(1)
- -> { @o.send :m=, 1, 2, 3, *x, 4 }.should raise_error(TypeError)
+ lambda { @o.send :m=, 1, 2, 3, *x, 4 }.should raise_error(TypeError)
end
end
end
@@ -512,15 +512,6 @@ describe "A method" do
end
evaluate <<-ruby do
- def m() end
- ruby
-
- m().should be_nil
- m(*[]).should be_nil
- m(**{}).should be_nil
- end
-
- evaluate <<-ruby do
def m(*) end
ruby
@@ -536,19 +527,15 @@ describe "A method" do
m().should == []
m(1).should == [1]
m(1, 2, 3).should == [1, 2, 3]
- m(*[]).should == []
- m(**{}).should == []
end
evaluate <<-ruby do
def m(a:) a end
ruby
- -> { m() }.should raise_error(ArgumentError)
+ lambda { m() }.should raise_error(ArgumentError)
m(a: 1).should == 1
- suppress_keyword_warning do
- -> { m("a" => 1, a: 1) }.should raise_error(ArgumentError)
- end
+ lambda { m("a" => 1, a: 1) }.should raise_error(ArgumentError)
end
evaluate <<-ruby do
@@ -565,7 +552,7 @@ describe "A method" do
m().should be_nil
m(a: 1, b: 2).should be_nil
- -> { m(1) }.should raise_error(ArgumentError)
+ lambda { m(1) }.should raise_error(ArgumentError)
end
evaluate <<-ruby do
@@ -574,10 +561,7 @@ describe "A method" do
m().should == {}
m(a: 1, b: 2).should == { a: 1, b: 2 }
- m(*[]).should == {}
- m(**{}).should == {}
- m(**{a: 1, b: 2}, **{a: 4, c: 7}).should == { a: 4, b: 2, c: 7 }
- -> { m(2) }.should raise_error(ArgumentError)
+ lambda { m(2) }.should raise_error(ArgumentError)
end
evaluate <<-ruby do
@@ -616,7 +600,7 @@ describe "A method" do
m(2, 3).should be_nil
m([2, 3, 4], [5, 6]).should be_nil
- -> { m a: 1 }.should raise_error(ArgumentError)
+ lambda { m a: 1 }.should raise_error(ArgumentError)
end
evaluate <<-ruby do
@@ -708,9 +692,7 @@ describe "A method" do
ruby
m(1, b: 2).should == [1, 2]
- suppress_keyword_warning do
- -> { m("a" => 1, b: 2) }.should raise_error(ArgumentError)
- end
+ lambda { m("a" => 1, b: 2) }.should raise_error(ArgumentError)
end
evaluate <<-ruby do
@@ -719,9 +701,7 @@ describe "A method" do
m(2).should == [2, 1]
m(1, b: 2).should == [1, 2]
- suppress_keyword_warning do
- m("a" => 1, b: 2).should == [{"a" => 1, b: 2}, 1]
- end
+ m("a" => 1, b: 2).should == [{"a" => 1, b: 2}, 1]
end
evaluate <<-ruby do
@@ -730,9 +710,7 @@ describe "A method" do
m(1).should == 1
m(1, a: 2, b: 3).should == 1
- suppress_keyword_warning do
- m("a" => 1, b: 2).should == {"a" => 1, b: 2}
- end
+ m("a" => 1, b: 2).should == {"a" => 1, b: 2}
end
evaluate <<-ruby do
@@ -741,9 +719,7 @@ describe "A method" do
m(1).should == [1, {}]
m(1, a: 2, b: 3).should == [1, {a: 2, b: 3}]
- suppress_keyword_warning do
- m("a" => 1, b: 2).should == [{"a" => 1, b: 2}, {}]
- end
+ m("a" => 1, b: 2).should == [{"a" => 1, b: 2}, {}]
end
evaluate <<-ruby do
@@ -818,8 +794,8 @@ describe "A method" do
def m(a=1, (*b), (*c)) [a, b, c] end
ruby
- -> { m() }.should raise_error(ArgumentError)
- -> { m(2) }.should raise_error(ArgumentError)
+ lambda { m() }.should raise_error(ArgumentError)
+ lambda { m(2) }.should raise_error(ArgumentError)
m(2, 3).should == [1, [2], [3]]
m(2, [3, 4], [5, 6]).should == [2, [3, 4], [5, 6]]
end
@@ -860,9 +836,7 @@ describe "A method" do
m(b: 2).should == [1, 2]
m(2, b: 1).should == [2, 1]
- suppress_keyword_warning do
- m("a" => 1, b: 2).should == [{"a" => 1}, 2]
- end
+ m("a" => 1, b: 2).should == [{"a" => 1}, 2]
end
evaluate <<-ruby do
@@ -872,31 +846,16 @@ describe "A method" do
m().should == [1, 2]
m(2).should == [2, 2]
m(b: 3).should == [1, 3]
- suppress_keyword_warning do
- m("a" => 1, b: 2).should == [{"a" => 1}, 2]
- end
- end
-
- ruby_version_is ""..."2.7" do
- evaluate <<-ruby do
- def m(a=1, **) a end
- ruby
-
- m().should == 1
- m(2, a: 1, b: 0).should == 2
- m("a" => 1, a: 2).should == {"a" => 1}
- end
+ m("a" => 1, b: 2).should == [{"a" => 1}, 2]
end
- ruby_version_is "2.7" do
- evaluate <<-ruby do
- def m(a=1, **) a end
- ruby
+ evaluate <<-ruby do
+ def m(a=1, **) a end
+ ruby
- m().should == 1
- m(2, a: 1, b: 0).should == 2
- m("a" => 1, a: 2).should == 1
- end
+ m().should == 1
+ m(2, a: 1, b: 0).should == 2
+ m("a" => 1, a: 2).should == {"a" => 1}
end
evaluate <<-ruby do
@@ -942,9 +901,7 @@ describe "A method" do
m(a: 1).should == 1
m(1, 2, a: 3).should == 3
- suppress_keyword_warning do
- m("a" => 1, a: 2).should == 2
- end
+ m("a" => 1, a: 2).should == 2
end
evaluate <<-ruby do
@@ -953,9 +910,7 @@ describe "A method" do
m(b: 1).should == [[], 1]
m(1, 2, b: 3).should == [[1, 2], 3]
- suppress_keyword_warning do
- m("a" => 1, b: 2).should == [[{"a" => 1}], 2]
- end
+ m("a" => 1, b: 2).should == [[{"a" => 1}], 2]
end
evaluate <<-ruby do
@@ -966,9 +921,7 @@ describe "A method" do
m(1, 2).should == 1
m(a: 2).should == 2
m(1, a: 2).should == 2
- suppress_keyword_warning do
- m("a" => 1, a: 2).should == 2
- end
+ m("a" => 1, a: 2).should == 2
end
evaluate <<-ruby do
@@ -977,9 +930,7 @@ describe "A method" do
m().should == [[], 1]
m(1, 2, 3, b: 4).should == [[1, 2, 3], 4]
- suppress_keyword_warning do
- m("a" => 1, b: 2).should == [[{"a" => 1}], 2]
- end
+ m("a" => 1, b: 2).should == [[{"a" => 1}], 2]
a = mock("splat")
a.should_not_receive(:to_ary)
@@ -996,194 +947,97 @@ describe "A method" do
h = mock("keyword splat")
h.should_receive(:to_hash).and_return({a: 1})
- suppress_keyword_warning do
- m(h).should be_nil
- end
+ m(h).should be_nil
h = mock("keyword splat")
error = RuntimeError.new("error while converting to a hash")
h.should_receive(:to_hash).and_raise(error)
- -> { m(h) }.should raise_error(error)
- end
-
- ruby_version_is ""..."2.7" do
- evaluate <<-ruby do
- def m(*a, **) a end
- ruby
-
- m().should == []
- m(1, 2, 3, a: 4, b: 5).should == [1, 2, 3]
- m("a" => 1, a: 1).should == [{"a" => 1}]
- m(1, **{a: 2}).should == [1]
-
- h = mock("keyword splat")
- h.should_receive(:to_hash)
- -> { m(**h) }.should raise_error(TypeError)
- end
-
- evaluate <<-ruby do
- def m(*, **k) k end
- ruby
-
- m().should == {}
- m(1, 2, 3, a: 4, b: 5).should == {a: 4, b: 5}
- m("a" => 1, a: 1).should == {a: 1}
-
- h = mock("keyword splat")
- h.should_receive(:to_hash).and_return({a: 1})
- m(h).should == {a: 1}
- end
-
- evaluate <<-ruby do
- def m(a = nil, **k) [a, k] end
- ruby
-
- m().should == [nil, {}]
- m("a" => 1).should == [{"a" => 1}, {}]
- m(a: 1).should == [nil, {a: 1}]
- m("a" => 1, a: 1).should == [{"a" => 1}, {a: 1}]
- m({ "a" => 1 }, a: 1).should == [{"a" => 1}, {a: 1}]
- m({a: 1}, {}).should == [{a: 1}, {}]
-
- h = {"a" => 1, b: 2}
- m(h).should == [{"a" => 1}, {b: 2}]
- h.should == {"a" => 1, b: 2}
-
- h = {"a" => 1}
- m(h).first.should == h
-
- h = {}
- r = m(h)
- r.first.should be_nil
- r.last.should == {}
-
- hh = {}
- h = mock("keyword splat empty hash")
- h.should_receive(:to_hash).and_return(hh)
- r = m(h)
- r.first.should be_nil
- r.last.should == {}
-
- h = mock("keyword splat")
- h.should_receive(:to_hash).and_return({"a" => 1, a: 2})
- m(h).should == [{"a" => 1}, {a: 2}]
- end
-
- evaluate <<-ruby do
- def m(*a, **k) [a, k] end
- ruby
-
- m().should == [[], {}]
- m(1).should == [[1], {}]
- m(a: 1, b: 2).should == [[], {a: 1, b: 2}]
- m(1, 2, 3, a: 2).should == [[1, 2, 3], {a: 2}]
-
- m("a" => 1).should == [[{"a" => 1}], {}]
- m(a: 1).should == [[], {a: 1}]
- m("a" => 1, a: 1).should == [[{"a" => 1}], {a: 1}]
- m({ "a" => 1 }, a: 1).should == [[{"a" => 1}], {a: 1}]
- m({a: 1}, {}).should == [[{a: 1}], {}]
- m({a: 1}, {"a" => 1}).should == [[{a: 1}, {"a" => 1}], {}]
-
- bo = BasicObject.new
- def bo.to_a; [1, 2, 3]; end
- def bo.to_hash; {:b => 2, :c => 3}; end
-
- m(*bo, **bo).should == [[1, 2, 3], {:b => 2, :c => 3}]
- end
- end
-
- ruby_version_is "2.7" do
- evaluate <<-ruby do
- def m(*a, **) a end
- ruby
-
- m().should == []
- m(1, 2, 3, a: 4, b: 5).should == [1, 2, 3]
- m("a" => 1, a: 1).should == []
- m(1, **{a: 2}).should == [1]
-
- h = mock("keyword splat")
- h.should_receive(:to_hash)
- -> { m(**h) }.should raise_error(TypeError)
- end
-
- evaluate <<-ruby do
- def m(*, **k) k end
- ruby
-
- m().should == {}
- m(1, 2, 3, a: 4, b: 5).should == {a: 4, b: 5}
- m("a" => 1, a: 1).should == {"a" => 1, a: 1}
-
- h = mock("keyword splat")
- h.should_receive(:to_hash).and_return({a: 1})
- suppress_warning do
- m(h).should == {a: 1}
- end
- end
-
- evaluate <<-ruby do
- def m(a = nil, **k) [a, k] end
- ruby
-
- m().should == [nil, {}]
- m("a" => 1).should == [nil, {"a" => 1}]
- m(a: 1).should == [nil, {a: 1}]
- m("a" => 1, a: 1).should == [nil, {"a" => 1, a: 1}]
- m({ "a" => 1 }, a: 1).should == [{"a" => 1}, {a: 1}]
- suppress_warning do
- m({a: 1}, {}).should == [{a: 1}, {}]
-
- h = {"a" => 1, b: 2}
- m(h).should == [{"a" => 1}, {b: 2}]
- h.should == {"a" => 1, b: 2}
-
- h = {"a" => 1}
- m(h).first.should == h
-
- h = {}
- r = m(h)
- r.first.should be_nil
- r.last.should == {}
-
- hh = {}
- h = mock("keyword splat empty hash")
- h.should_receive(:to_hash).and_return(hh)
- r = m(h)
- r.first.should be_nil
- r.last.should == {}
-
- h = mock("keyword splat")
- h.should_receive(:to_hash).and_return({"a" => 1, a: 2})
- m(h).should == [{"a" => 1}, {a: 2}]
- end
- end
-
- evaluate <<-ruby do
- def m(*a, **k) [a, k] end
- ruby
-
- m().should == [[], {}]
- m(1).should == [[1], {}]
- m(a: 1, b: 2).should == [[], {a: 1, b: 2}]
- m(1, 2, 3, a: 2).should == [[1, 2, 3], {a: 2}]
-
- m("a" => 1).should == [[], {"a" => 1}]
- m(a: 1).should == [[], {a: 1}]
- m("a" => 1, a: 1).should == [[], {"a" => 1, a: 1}]
- m({ "a" => 1 }, a: 1).should == [[{"a" => 1}], {a: 1}]
- suppress_warning do
- m({a: 1}, {}).should == [[{a: 1}], {}]
- end
- m({a: 1}, {"a" => 1}).should == [[{a: 1}, {"a" => 1}], {}]
+ lambda { m(h) }.should raise_error(error)
+ end
+
+ evaluate <<-ruby do
+ def m(*a, **) a end
+ ruby
+
+ m().should == []
+ m(1, 2, 3, a: 4, b: 5).should == [1, 2, 3]
+ m("a" => 1, a: 1).should == [{"a" => 1}]
+ m(1, **{a: 2}).should == [1]
+
+ h = mock("keyword splat")
+ h.should_receive(:to_hash)
+ lambda { m(**h) }.should raise_error(TypeError)
+ end
+
+ evaluate <<-ruby do
+ def m(*, **k) k end
+ ruby
+
+ m().should == {}
+ m(1, 2, 3, a: 4, b: 5).should == {a: 4, b: 5}
+ m("a" => 1, a: 1).should == {a: 1}
+
+ h = mock("keyword splat")
+ h.should_receive(:to_hash).and_return({a: 1})
+ m(h).should == {a: 1}
+ end
+
+ evaluate <<-ruby do
+ def m(a = nil, **k) [a, k] end
+ ruby
+
+ m().should == [nil, {}]
+ m("a" => 1).should == [{"a" => 1}, {}]
+ m(a: 1).should == [nil, {a: 1}]
+ m("a" => 1, a: 1).should == [{"a" => 1}, {a: 1}]
+ m({ "a" => 1 }, a: 1).should == [{"a" => 1}, {a: 1}]
+ m({a: 1}, {}).should == [{a: 1}, {}]
+
+ h = {"a" => 1, b: 2}
+ m(h).should == [{"a" => 1}, {b: 2}]
+ h.should == {"a" => 1, b: 2}
+
+ h = {"a" => 1}
+ m(h).first.should == h
- bo = BasicObject.new
- def bo.to_a; [1, 2, 3]; end
- def bo.to_hash; {:b => 2, :c => 3}; end
+ h = {}
+ r = m(h)
+ r.first.should be_nil
+ r.last.should == {}
- m(*bo, **bo).should == [[1, 2, 3], {:b => 2, :c => 3}]
- end
+ hh = {}
+ h = mock("keyword splat empty hash")
+ h.should_receive(:to_hash).and_return(hh)
+ r = m(h)
+ r.first.should be_nil
+ r.last.should == {}
+
+ h = mock("keyword splat")
+ h.should_receive(:to_hash).and_return({"a" => 1, a: 2})
+ m(h).should == [{"a" => 1}, {a: 2}]
+ end
+
+ evaluate <<-ruby do
+ def m(*a, **k) [a, k] end
+ ruby
+
+ m().should == [[], {}]
+ m(1).should == [[1], {}]
+ m(a: 1, b: 2).should == [[], {a: 1, b: 2}]
+ m(1, 2, 3, a: 2).should == [[1, 2, 3], {a: 2}]
+
+ m("a" => 1).should == [[{"a" => 1}], {}]
+ m(a: 1).should == [[], {a: 1}]
+ m("a" => 1, a: 1).should == [[{"a" => 1}], {a: 1}]
+ m({ "a" => 1 }, a: 1).should == [[{"a" => 1}], {a: 1}]
+ m({a: 1}, {}).should == [[{a: 1}], {}]
+ m({a: 1}, {"a" => 1}).should == [[{a: 1}, {"a" => 1}], {}]
+
+ bo = BasicObject.new
+ def bo.to_a; [1, 2, 3]; end
+ def bo.to_hash; {:b => 2, :c => 3}; end
+
+ m(*bo, **bo).should == [[1, 2, 3], {:b => 2, :c => 3}]
end
evaluate <<-ruby do
@@ -1209,9 +1063,7 @@ describe "A method" do
ruby
m(a: 1, b: 2).should == [1, 2]
- suppress_keyword_warning do
- -> { m("a" => 1, a: 1, b: 2) }.should raise_error(ArgumentError)
- end
+ lambda { m("a" => 1, a: 1, b: 2) }.should raise_error(ArgumentError)
end
evaluate <<-ruby do
@@ -1220,51 +1072,25 @@ describe "A method" do
m(a: 1).should == [1, 1]
m(a: 1, b: 2).should == [1, 2]
- suppress_keyword_warning do
- -> { m("a" => 1, a: 1, b: 2) }.should raise_error(ArgumentError)
- end
+ lambda { m("a" => 1, a: 1, b: 2) }.should raise_error(ArgumentError)
end
- ruby_version_is ''...'2.7' do
- evaluate <<-ruby do
- def m(a:, **) a end
- ruby
-
- m(a: 1).should == 1
- m(a: 1, b: 2).should == 1
- -> { m("a" => 1, a: 1, b: 2) }.should raise_error(ArgumentError)
- end
-
- evaluate <<-ruby do
- def m(a:, **k) [a, k] end
- ruby
+ evaluate <<-ruby do
+ def m(a:, **) a end
+ ruby
- m(a: 1).should == [1, {}]
- m(a: 1, b: 2, c: 3).should == [1, {b: 2, c: 3}]
- -> { m("a" => 1, a: 1, b: 2) }.should raise_error(ArgumentError)
- end
+ m(a: 1).should == 1
+ m(a: 1, b: 2).should == 1
+ lambda { m("a" => 1, a: 1, b: 2) }.should raise_error(ArgumentError)
end
- ruby_version_is '2.7' do
- evaluate <<-ruby do
- def m(a:, **) a end
- ruby
-
- m(a: 1).should == 1
- m(a: 1, b: 2).should == 1
- m("a" => 1, a: 1, b: 2).should == 1
- end
-
- evaluate <<-ruby do
- def m(a:, **k) [a, k] end
- ruby
+ evaluate <<-ruby do
+ def m(a:, **k) [a, k] end
+ ruby
- m(a: 1).should == [1, {}]
- m(a: 1, b: 2, c: 3).should == [1, {b: 2, c: 3}]
- suppress_warning do
- m("a" => 1, a: 1, b: 2).should == [1, {"a" => 1, b: 2}]
- end
- end
+ m(a: 1).should == [1, {}]
+ m(a: 1, b: 2, c: 3).should == [1, {b: 2, c: 3}]
+ lambda { m("a" => 1, a: 1, b: 2) }.should raise_error(ArgumentError)
end
evaluate <<-ruby do
@@ -1365,35 +1191,18 @@ describe "A method" do
def m(a, b = nil, c = nil, d, e: nil, **f)
[a, b, c, d, e, f]
end
- ruby
+ ruby
result = m(1, 2)
result.should == [1, nil, nil, 2, nil, {}]
- suppress_warning do
- result = m(1, 2, {foo: :bar})
- result.should == [1, nil, nil, 2, nil, {foo: :bar}]
- end
+ result = m(1, 2, {foo: :bar})
+ result.should == [1, nil, nil, 2, nil, {foo: :bar}]
result = m(1, {foo: :bar})
result.should == [1, nil, nil, {foo: :bar}, nil, {}]
end
end
-
- context "assigns keyword arguments from a passed Hash without modifying it" do
- evaluate <<-ruby do
- def m(a: nil); a; end
- ruby
-
- options = {a: 1}.freeze
- -> do
- suppress_warning do
- m(options).should == 1
- end
- end.should_not raise_error
- options.should == {a: 1}
- end
- end
end
describe "A method call with a space between method name and parentheses" do
@@ -1423,11 +1232,11 @@ describe "A method call with a space between method name and parentheses" do
context "when 2+ arguments provided" do
it "raises a syntax error" do
- -> {
+ lambda {
eval("m (1, 2)")
}.should raise_error(SyntaxError)
- -> {
+ lambda {
eval("m (1, 2, 3)")
}.should raise_error(SyntaxError)
end
diff --git a/spec/ruby/language/module_spec.rb b/spec/ruby/language/module_spec.rb
index 1b41e184bb..d5ca71b3b4 100644
--- a/spec/ruby/language/module_spec.rb
+++ b/spec/ruby/language/module_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../spec_helper'
-require_relative 'fixtures/module'
+require File.expand_path('../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/module', __FILE__)
describe "The module keyword" do
it "creates a new module without semicolon" do
@@ -34,29 +34,29 @@ describe "The module keyword" do
end
it "raises a TypeError if the constant is a Class" do
- -> do
+ lambda do
module ModuleSpecs::Modules::Klass; end
end.should raise_error(TypeError)
end
it "raises a TypeError if the constant is a String" do
- -> { module ModuleSpecs::Modules::A; end }.should raise_error(TypeError)
+ lambda { module ModuleSpecs::Modules::A; end }.should raise_error(TypeError)
end
it "raises a TypeError if the constant is a Fixnum" do
- -> { module ModuleSpecs::Modules::B; end }.should raise_error(TypeError)
+ lambda { module ModuleSpecs::Modules::B; end }.should raise_error(TypeError)
end
it "raises a TypeError if the constant is nil" do
- -> { module ModuleSpecs::Modules::C; end }.should raise_error(TypeError)
+ lambda { module ModuleSpecs::Modules::C; end }.should raise_error(TypeError)
end
it "raises a TypeError if the constant is true" do
- -> { module ModuleSpecs::Modules::D; end }.should raise_error(TypeError)
+ lambda { module ModuleSpecs::Modules::D; end }.should raise_error(TypeError)
end
it "raises a TypeError if the constant is false" do
- -> { module ModuleSpecs::Modules::D; end }.should raise_error(TypeError)
+ lambda { module ModuleSpecs::Modules::D; end }.should raise_error(TypeError)
end
end
diff --git a/spec/ruby/language/next_spec.rb b/spec/ruby/language/next_spec.rb
index 6fbfc4a54d..67da5224dc 100644
--- a/spec/ruby/language/next_spec.rb
+++ b/spec/ruby/language/next_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../spec_helper'
-require_relative 'fixtures/next'
+require File.expand_path('../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/next', __FILE__)
describe "The next statement from within the block" do
before :each do
@@ -8,7 +8,7 @@ describe "The next statement from within the block" do
it "ends block execution" do
a = []
- -> {
+ lambda {
a << 1
next
a << 2
@@ -17,15 +17,15 @@ describe "The next statement from within the block" do
end
it "causes block to return nil if invoked without arguments" do
- -> { 123; next; 456 }.call.should == nil
+ lambda { 123; next; 456 }.call.should == nil
end
it "causes block to return nil if invoked with an empty expression" do
- -> { next (); 456 }.call.should be_nil
+ lambda { next (); 456 }.call.should be_nil
end
it "returns the argument passed" do
- -> { 123; next 234; 345 }.call.should == 234
+ lambda { 123; next 234; 345 }.call.should == 234
end
it "returns to the invoking method" do
@@ -102,14 +102,14 @@ describe "The next statement from within the block" do
it "passes the value returned by a method with omitted parenthesis and passed block" do
obj = NextSpecs::Block.new
- -> { next obj.method :value do |x| x end }.call.should == :value
+ lambda { next obj.method :value do |x| x end }.call.should == :value
end
end
describe "The next statement" do
describe "in a method" do
it "is invalid and raises a SyntaxError" do
- -> {
+ lambda {
eval("def m; next; end")
}.should raise_error(SyntaxError)
end
diff --git a/spec/ruby/language/not_spec.rb b/spec/ruby/language/not_spec.rb
index 052af9b256..a0cf6b15a6 100644
--- a/spec/ruby/language/not_spec.rb
+++ b/spec/ruby/language/not_spec.rb
@@ -1,4 +1,4 @@
-require_relative '../spec_helper'
+require File.expand_path('../../spec_helper', __FILE__)
describe "The not keyword" do
it "negates a `true' value" do
diff --git a/spec/ruby/language/numbers_spec.rb b/spec/ruby/language/numbers_spec.rb
index c82a630632..e8c82f09a7 100644
--- a/spec/ruby/language/numbers_spec.rb
+++ b/spec/ruby/language/numbers_spec.rb
@@ -1,4 +1,4 @@
-require_relative '../spec_helper'
+require File.expand_path('../../spec_helper', __FILE__)
describe "A number literal" do
@@ -11,7 +11,7 @@ describe "A number literal" do
end
it "cannot have a leading underscore" do
- -> { eval("_4_2") }.should raise_error(NameError)
+ lambda { eval("_4_2") }.should raise_error(NameError)
end
it "can have a decimal point" do
@@ -20,8 +20,8 @@ describe "A number literal" do
it "must have a digit before the decimal point" do
0.75.should == 0.75
- -> { eval(".75") }.should raise_error(SyntaxError)
- -> { eval("-.75") }.should raise_error(SyntaxError)
+ lambda { eval(".75") }.should raise_error(SyntaxError)
+ lambda { eval("-.75") }.should raise_error(SyntaxError)
end
it "can have an exponent" do
diff --git a/spec/ruby/language/optional_assignments_spec.rb b/spec/ruby/language/optional_assignments_spec.rb
index 3d9e0dbb65..0ab28985ed 100644
--- a/spec/ruby/language/optional_assignments_spec.rb
+++ b/spec/ruby/language/optional_assignments_spec.rb
@@ -1,4 +1,4 @@
-require_relative '../spec_helper'
+require File.expand_path('../../spec_helper', __FILE__)
describe 'Optional variable assignments' do
describe 'using ||=' do
@@ -42,18 +42,6 @@ describe 'Optional variable assignments' do
a.should == 10
end
-
- it 'returns the new value if set to false' do
- a = false
-
- (a ||= 20).should == 20
- end
-
- it 'returns the original value if truthy' do
- a = 10
-
- (a ||= 20).should == 10
- end
end
describe 'using a accessor' do
@@ -101,49 +89,6 @@ describe 'Optional variable assignments' do
@a.b.should == 10
end
-
- it 'returns the new value if set to false' do
- def @a.b=(x)
- :v
- end
-
- @a.b = false
- (@a.b ||= 20).should == 20
- end
-
- it 'returns the original value if truthy' do
- def @a.b=(x)
- @b = x
- :v
- end
-
- @a.b = 10
- (@a.b ||= 20).should == 10
- end
-
- it 'works when writer is private' do
- klass = Class.new do
- def t
- self.b = false
- (self.b ||= 10).should == 10
- (self.b ||= 20).should == 10
- end
-
- def b
- @b
- end
-
- def b=(x)
- @b = x
- :v
- end
-
- private :b=
- end
-
- klass.new.t
- end
-
end
end
@@ -236,82 +181,10 @@ describe 'Optional variable assignments' do
@a.b.should == 20
end
end
-
- describe 'using a #[]' do
- before do
- @a = {}
- klass = Class.new do
- def [](k)
- @hash ||= {}
- @hash[k]
- end
-
- def []=(k, v)
- @hash ||= {}
- @hash[k] = v
- 7
- end
- end
- @b = klass.new
- end
-
- it 'leaves new variable unassigned' do
- @a[:k] &&= 10
-
- @a.key?(:k).should == false
- end
-
- it 'leaves false' do
- @a[:k] = false
- @a[:k] &&= 10
-
- @a[:k].should == false
- end
-
- it 'leaves nil' do
- @a[:k] = nil
- @a[:k] &&= 10
-
- @a[:k].should == nil
- end
-
- it 'does not evaluate the right side when not needed' do
- @a[:k] = nil
- @a[:k] &&= raise('should not be executed')
- @a[:k].should == nil
- end
-
- it 'does re-assign a variable with a truthy value' do
- @a[:k] = 10
- @a[:k] &&= 20
-
- @a[:k].should == 20
- end
-
- it 'does re-assign a variable with a truthy value when using an inline rescue' do
- @a[:k] = 10
- @a[:k] &&= 20 rescue 30
-
- @a[:k].should == 20
- end
-
- it 'returns the assigned value, not the result of the []= method with ||=' do
- (@b[:k] ||= 12).should == 12
- end
-
- it 'returns the assigned value, not the result of the []= method with +=' do
- @b[:k] = 17
- (@b[:k] += 12).should == 29
- end
- end
end
- describe 'using compounded constants' do
- before :each do
- Object.send(:remove_const, :A) if defined? Object::A
- end
-
- after :each do
+ describe 'using compunded constants' do
+ before do
Object.send(:remove_const, :A) if defined? Object::A
end
@@ -335,7 +208,7 @@ describe 'Optional variable assignments' do
end
it 'with &&= assignments will fail with non-existent constants' do
- -> { Object::A &&= 10 }.should raise_error(NameError)
+ lambda { Object::A &&= 10 }.should raise_error(NameError)
end
it 'with operator assignments' do
@@ -347,7 +220,7 @@ describe 'Optional variable assignments' do
end
it 'with operator assignments will fail with non-existent constants' do
- -> { Object::A += 10 }.should raise_error(NameError)
+ lambda { Object::A += 10 }.should raise_error(NameError)
end
end
end
diff --git a/spec/ruby/language/or_spec.rb b/spec/ruby/language/or_spec.rb
index fb75e788f1..150d693996 100644
--- a/spec/ruby/language/or_spec.rb
+++ b/spec/ruby/language/or_spec.rb
@@ -1,4 +1,4 @@
-require_relative '../spec_helper'
+require File.expand_path('../../spec_helper', __FILE__)
describe "The || operator" do
it "evaluates to true if any of its operands are true" do
@@ -35,15 +35,15 @@ describe "The || operator" do
it "has a higher precedence than 'break' in 'break true || false'" do
# see also 'break true or false' below
- -> { break false || true }.call.should be_true
+ lambda { break false || true }.call.should be_true
end
it "has a higher precedence than 'next' in 'next true || false'" do
- -> { next false || true }.call.should be_true
+ lambda { next false || true }.call.should be_true
end
it "has a higher precedence than 'return' in 'return true || false'" do
- -> { return false || true }.call.should be_true
+ lambda { return false || true }.call.should be_true
end
end
@@ -77,14 +77,14 @@ describe "The or operator" do
it "has a lower precedence than 'break' in 'break true or false'" do
# see also 'break true || false' above
- -> { eval "break true or false" }.should raise_error(SyntaxError, /void value expression/)
+ lambda { eval "break true or false" }.should raise_error(SyntaxError, /void value expression/)
end
it "has a lower precedence than 'next' in 'next true or false'" do
- -> { eval "next true or false" }.should raise_error(SyntaxError, /void value expression/)
+ lambda { eval "next true or false" }.should raise_error(SyntaxError, /void value expression/)
end
it "has a lower precedence than 'return' in 'return true or false'" do
- -> { eval "return true or false" }.should raise_error(SyntaxError, /void value expression/)
+ lambda { eval "return true or false" }.should raise_error(SyntaxError, /void value expression/)
end
end
diff --git a/spec/ruby/language/order_spec.rb b/spec/ruby/language/order_spec.rb
index d550f6b3f4..d02bf04077 100644
--- a/spec/ruby/language/order_spec.rb
+++ b/spec/ruby/language/order_spec.rb
@@ -1,4 +1,4 @@
-require_relative '../spec_helper'
+require File.expand_path('../../spec_helper', __FILE__)
describe "A method call" do
before :each do
diff --git a/spec/ruby/language/precedence_spec.rb b/spec/ruby/language/precedence_spec.rb
index 5a3c2861ce..90734022ff 100644
--- a/spec/ruby/language/precedence_spec.rb
+++ b/spec/ruby/language/precedence_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../spec_helper'
-require_relative 'fixtures/precedence'
+require File.expand_path('../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/precedence', __FILE__)
# Specifying the behavior of operators in combination could
# lead to combinatorial explosion. A better way seems to be
@@ -136,7 +136,7 @@ describe "Operators" do
# Guard against the Mathn library
# TODO: Make these specs not rely on specific behaviour / result values
# by using mocks.
- guard -> { !defined?(Math.rsqrt) } do
+ conflicts_with :Prime do
(2*1/2).should_not == 2*(1/2)
end
@@ -253,12 +253,12 @@ describe "Operators" do
end
it "<=> == === != =~ !~ are non-associative" do
- -> { eval("1 <=> 2 <=> 3") }.should raise_error(SyntaxError)
- -> { eval("1 == 2 == 3") }.should raise_error(SyntaxError)
- -> { eval("1 === 2 === 3") }.should raise_error(SyntaxError)
- -> { eval("1 != 2 != 3") }.should raise_error(SyntaxError)
- -> { eval("1 =~ 2 =~ 3") }.should raise_error(SyntaxError)
- -> { eval("1 !~ 2 !~ 3") }.should raise_error(SyntaxError)
+ lambda { eval("1 <=> 2 <=> 3") }.should raise_error(SyntaxError)
+ lambda { eval("1 == 2 == 3") }.should raise_error(SyntaxError)
+ lambda { eval("1 === 2 === 3") }.should raise_error(SyntaxError)
+ lambda { eval("1 != 2 != 3") }.should raise_error(SyntaxError)
+ lambda { eval("1 =~ 2 =~ 3") }.should raise_error(SyntaxError)
+ lambda { eval("1 !~ 2 !~ 3") }.should raise_error(SyntaxError)
end
it "<=> == === != =~ !~ have higher precedence than &&" do
@@ -292,18 +292,19 @@ describe "Operators" do
end
it ".. ... are non-associative" do
- -> { eval("1..2..3") }.should raise_error(SyntaxError)
- -> { eval("1...2...3") }.should raise_error(SyntaxError)
+ lambda { eval("1..2..3") }.should raise_error(SyntaxError)
+ lambda { eval("1...2...3") }.should raise_error(SyntaxError)
end
- it ".. ... have higher precedence than ? :" do
- # Use variables to avoid warnings
- from = 1
- to = 2
- # These are flip-flop, not Range instances
- (from..to ? 3 : 4).should == 3
- (from...to ? 3 : 4).should == 3
- end
+# XXX: this is commented now due to a bug in compiler, which cannot
+# distinguish between range and flip-flop operator so far. zenspider is
+# currently working on a new lexer, which will be able to do that.
+# As soon as it's done, these piece should be reenabled.
+#
+# it ".. ... have higher precedence than ? :" do
+# (1..2 ? 3 : 4).should == 3
+# (1...2 ? 3 : 4).should == 3
+# end
it "? : is right-associative" do
(true ? 2 : 3 ? 4 : 5).should == 2
diff --git a/spec/ruby/language/predefined/data_spec.rb b/spec/ruby/language/predefined/data_spec.rb
index 921d236ee9..f616879527 100644
--- a/spec/ruby/language/predefined/data_spec.rb
+++ b/spec/ruby/language/predefined/data_spec.rb
@@ -1,4 +1,4 @@
-require_relative '../../spec_helper'
+require File.expand_path('../../../spec_helper', __FILE__)
describe "The DATA constant" do
it "exists when the main script contains __END__" do
@@ -23,25 +23,6 @@ describe "The DATA constant" do
str.chomp.should == "data only"
end
- it "returns a File object with the right offset" do
- ruby_exe(fixture(__FILE__, "data_offset.rb")).should == "File\n121\n"
- end
-
- it "is set even if there is no data after __END__" do
- ruby_exe(fixture(__FILE__, "empty_data.rb")).should == "31\n\"\"\n"
- end
-
- it "is set even if there is no newline after __END__" do
- path = tmp("no_newline_data.rb")
- code = File.binread(fixture(__FILE__, "empty_data.rb"))
- touch(path, "wb") { |f| f.write code.chomp }
- begin
- ruby_exe(path).should == "30\n\"\"\n"
- ensure
- rm_r path
- end
- end
-
it "rewinds to the head of the main script" do
ruby_exe(fixture(__FILE__, "data5.rb")).chomp.should == "DATA.rewind"
end
diff --git a/spec/ruby/language/predefined/fixtures/data2.rb b/spec/ruby/language/predefined/fixtures/data2.rb
index a764ca56d1..0f714b06d4 100644
--- a/spec/ruby/language/predefined/fixtures/data2.rb
+++ b/spec/ruby/language/predefined/fixtures/data2.rb
@@ -1,3 +1,4 @@
-require_relative 'data4'
+
+require File.expand_path("../data4.rb", __FILE__)
p Object.const_defined?(:DATA)
diff --git a/spec/ruby/language/predefined/fixtures/data3.rb b/spec/ruby/language/predefined/fixtures/data3.rb
index e37313c68b..6cbf63dae6 100644
--- a/spec/ruby/language/predefined/fixtures/data3.rb
+++ b/spec/ruby/language/predefined/fixtures/data3.rb
@@ -1,4 +1,5 @@
-require_relative 'data4'
+
+require File.expand_path("../data4.rb", __FILE__)
puts DATA.read
diff --git a/spec/ruby/language/predefined/fixtures/data_offset.rb b/spec/ruby/language/predefined/fixtures/data_offset.rb
deleted file mode 100644
index 9829b3f87f..0000000000
--- a/spec/ruby/language/predefined/fixtures/data_offset.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-# some comment
-
-foo = <<HEREDOC
-some heredoc to make the
-spec more interesting
-HEREDOC
-
-p DATA.class
-p DATA.pos
-
-__END__
-data offset
diff --git a/spec/ruby/language/predefined/fixtures/empty_data.rb b/spec/ruby/language/predefined/fixtures/empty_data.rb
deleted file mode 100644
index c6d9bc6f1f..0000000000
--- a/spec/ruby/language/predefined/fixtures/empty_data.rb
+++ /dev/null
@@ -1,3 +0,0 @@
-p DATA.pos
-p DATA.read
-__END__
diff --git a/spec/ruby/language/predefined/fixtures/toplevel_binding_dynamic.rb b/spec/ruby/language/predefined/fixtures/toplevel_binding_dynamic.rb
deleted file mode 100644
index f7809109fa..0000000000
--- a/spec/ruby/language/predefined/fixtures/toplevel_binding_dynamic.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-p TOPLEVEL_BINDING.local_variables.sort
-TOPLEVEL_BINDING.local_variable_set(:dynamic_set_main, 2)
-p TOPLEVEL_BINDING.local_variables.sort
-main_script = 3
diff --git a/spec/ruby/language/predefined/fixtures/toplevel_binding_dynamic_required.rb b/spec/ruby/language/predefined/fixtures/toplevel_binding_dynamic_required.rb
deleted file mode 100644
index 7ccf329680..0000000000
--- a/spec/ruby/language/predefined/fixtures/toplevel_binding_dynamic_required.rb
+++ /dev/null
@@ -1,2 +0,0 @@
-TOPLEVEL_BINDING.local_variable_set(:dynamic_set_required, 1)
-p TOPLEVEL_BINDING.local_variables
diff --git a/spec/ruby/language/predefined/fixtures/toplevel_binding_id.rb b/spec/ruby/language/predefined/fixtures/toplevel_binding_id.rb
deleted file mode 100644
index 3626ea1f10..0000000000
--- a/spec/ruby/language/predefined/fixtures/toplevel_binding_id.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-a = TOPLEVEL_BINDING.object_id
-require_relative 'toplevel_binding_id_required'
-c = eval('TOPLEVEL_BINDING.object_id')
-p [a, $b, c].uniq.size
diff --git a/spec/ruby/language/predefined/fixtures/toplevel_binding_id_required.rb b/spec/ruby/language/predefined/fixtures/toplevel_binding_id_required.rb
deleted file mode 100644
index b31b6e32a0..0000000000
--- a/spec/ruby/language/predefined/fixtures/toplevel_binding_id_required.rb
+++ /dev/null
@@ -1 +0,0 @@
-$b = TOPLEVEL_BINDING.object_id
diff --git a/spec/ruby/language/predefined/fixtures/toplevel_binding_required_before.rb b/spec/ruby/language/predefined/fixtures/toplevel_binding_required_before.rb
deleted file mode 100644
index 58924a5800..0000000000
--- a/spec/ruby/language/predefined/fixtures/toplevel_binding_required_before.rb
+++ /dev/null
@@ -1,2 +0,0 @@
-required = true
-p [:required_before, TOPLEVEL_BINDING.local_variables]
diff --git a/spec/ruby/language/predefined/fixtures/toplevel_binding_values.rb b/spec/ruby/language/predefined/fixtures/toplevel_binding_values.rb
deleted file mode 100644
index 42bd67f347..0000000000
--- a/spec/ruby/language/predefined/fixtures/toplevel_binding_values.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-p TOPLEVEL_BINDING.local_variable_get(:a)
-p TOPLEVEL_BINDING.local_variable_get(:b)
-a = 1
-p TOPLEVEL_BINDING.local_variable_get(:a)
-p TOPLEVEL_BINDING.local_variable_get(:b)
-b = 2
-a = 3
-p TOPLEVEL_BINDING.local_variable_get(:a)
-p TOPLEVEL_BINDING.local_variable_get(:b)
diff --git a/spec/ruby/language/predefined/fixtures/toplevel_binding_variables.rb b/spec/ruby/language/predefined/fixtures/toplevel_binding_variables.rb
deleted file mode 100644
index 151f4340ef..0000000000
--- a/spec/ruby/language/predefined/fixtures/toplevel_binding_variables.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-main_script = 1
-require_relative 'toplevel_binding_variables_required'
-eval('eval_var = 3')
-p TOPLEVEL_BINDING.local_variables
diff --git a/spec/ruby/language/predefined/fixtures/toplevel_binding_variables_required.rb b/spec/ruby/language/predefined/fixtures/toplevel_binding_variables_required.rb
deleted file mode 100644
index 614547fe16..0000000000
--- a/spec/ruby/language/predefined/fixtures/toplevel_binding_variables_required.rb
+++ /dev/null
@@ -1,2 +0,0 @@
-required = 2
-p [:required_after, TOPLEVEL_BINDING.local_variables]
diff --git a/spec/ruby/language/predefined/toplevel_binding_spec.rb b/spec/ruby/language/predefined/toplevel_binding_spec.rb
deleted file mode 100644
index 69ac28618c..0000000000
--- a/spec/ruby/language/predefined/toplevel_binding_spec.rb
+++ /dev/null
@@ -1,34 +0,0 @@
-require_relative '../../spec_helper'
-
-describe "The TOPLEVEL_BINDING constant" do
- it "only includes local variables defined in the main script, not in required files or eval" do
- binding_toplevel_variables = ruby_exe(fixture(__FILE__, "toplevel_binding_variables.rb"))
- binding_toplevel_variables.should == "[:required_after, [:main_script]]\n[:main_script]\n"
- end
-
- it "has no local variables in files required before the main script" do
- required = fixture(__FILE__, 'toplevel_binding_required_before.rb')
- out = ruby_exe("a=1; p TOPLEVEL_BINDING.local_variables.sort; b=2", options: "-r#{required}")
- out.should == "[:required_before, []]\n[:a, :b]\n"
- end
-
- it "merges local variables of the main script with dynamically-defined Binding variables" do
- required = fixture(__FILE__, 'toplevel_binding_dynamic_required.rb')
- out = ruby_exe(fixture(__FILE__, 'toplevel_binding_dynamic.rb'), options: "-r#{required}")
- out.should == <<EOS
-[:dynamic_set_required]
-[:dynamic_set_required, :main_script]
-[:dynamic_set_main, :dynamic_set_required, :main_script]
-EOS
- end
-
- it "gets updated variables values as they are defined and set" do
- out = ruby_exe(fixture(__FILE__, "toplevel_binding_values.rb"))
- out.should == "nil\nnil\n1\nnil\n3\n2\n"
- end
-
- it "is always the same object for all top levels" do
- binding_toplevel_id = ruby_exe(fixture(__FILE__, "toplevel_binding_id.rb"))
- binding_toplevel_id.should == "1\n"
- end
-end
diff --git a/spec/ruby/language/predefined_spec.rb b/spec/ruby/language/predefined_spec.rb
index cdf2c28dcb..f827fb2eb5 100644
--- a/spec/ruby/language/predefined_spec.rb
+++ b/spec/ruby/language/predefined_spec.rb
@@ -1,4 +1,4 @@
-require_relative '../spec_helper'
+require File.expand_path('../../spec_helper', __FILE__)
require 'stringio'
# The following tables are excerpted from Programming Ruby: The Pragmatic Programmer's Guide'
@@ -30,11 +30,11 @@ $` String The string preceding the match in a successful
is local to the current scope. [r/o, thread]
$' String The string following the match in a successful pattern match. This variable
is local to the current scope. [r/o, thread]
-$1 to $<N> String The contents of successive groups matched in a successful pattern match. In
+$1 to $9 String The contents of successive groups matched in a successful pattern match. In
"cat" =~/(c|a)(t|z)/, $1 will be set to “a†and $2 to “tâ€. This variable
is local to the current scope. [r/o, thread]
$~ MatchData An object that encapsulates the results of a successful pattern match. The
- variables $&, $`, $', and $1 to $<N> are all derived from $~. Assigning to $~
+ variables $&, $`, $', and $1 to $9 are all derived from $~. Assigning to $~
changes the values of these derived variables. This variable is local to the
current scope. [thread]
=end
@@ -44,11 +44,11 @@ describe "Predefined global $~" do
it "is set to contain the MatchData object of the last match if successful" do
md = /foo/.match 'foo'
$~.should be_kind_of(MatchData)
- $~.should equal md
+ $~.object_id.should == md.object_id
/bar/ =~ 'bar'
$~.should be_kind_of(MatchData)
- $~.should_not equal md
+ $~.object_id.should_not == md.object_id
end
it "is set to nil if the last match was unsuccessful" do
@@ -92,8 +92,8 @@ describe "Predefined global $~" do
$~ = /foo/.match("foo")
$~.should be_an_instance_of(MatchData)
- -> { $~ = Object.new }.should raise_error(TypeError)
- -> { $~ = 1 }.should raise_error(TypeError)
+ lambda { $~ = Object.new }.should raise_error(TypeError)
+ lambda { $~ = 1 }.should raise_error(TypeError)
end
it "changes the value of derived capture globals when assigned" do
@@ -136,9 +136,11 @@ describe "Predefined global $&" do
$&.should == 'foo'
end
- it "sets the encoding to the encoding of the source String" do
- "abc".force_encoding(Encoding::EUC_JP) =~ /b/
- $&.encoding.should equal(Encoding::EUC_JP)
+ with_feature :encoding do
+ it "sets the encoding to the encoding of the source String" do
+ "abc".force_encoding(Encoding::EUC_JP) =~ /b/
+ $&.encoding.should equal(Encoding::EUC_JP)
+ end
end
end
@@ -149,14 +151,16 @@ describe "Predefined global $`" do
$`.should == 'bar'
end
- it "sets the encoding to the encoding of the source String" do
- "abc".force_encoding(Encoding::EUC_JP) =~ /b/
- $`.encoding.should equal(Encoding::EUC_JP)
- end
+ with_feature :encoding do
+ it "sets the encoding to the encoding of the source String" do
+ "abc".force_encoding(Encoding::EUC_JP) =~ /b/
+ $`.encoding.should equal(Encoding::EUC_JP)
+ end
- it "sets an empty result to the encoding of the source String" do
- "abc".force_encoding(Encoding::ISO_8859_1) =~ /a/
- $`.encoding.should equal(Encoding::ISO_8859_1)
+ it "sets an empty result to the encoding of the source String" do
+ "abc".force_encoding(Encoding::ISO_8859_1) =~ /a/
+ $`.encoding.should equal(Encoding::ISO_8859_1)
+ end
end
end
@@ -167,14 +171,16 @@ describe "Predefined global $'" do
$'.should == 'baz'
end
- it "sets the encoding to the encoding of the source String" do
- "abc".force_encoding(Encoding::EUC_JP) =~ /b/
- $'.encoding.should equal(Encoding::EUC_JP)
- end
+ with_feature :encoding do
+ it "sets the encoding to the encoding of the source String" do
+ "abc".force_encoding(Encoding::EUC_JP) =~ /b/
+ $'.encoding.should equal(Encoding::EUC_JP)
+ end
- it "sets an empty result to the encoding of the source String" do
- "abc".force_encoding(Encoding::ISO_8859_1) =~ /c/
- $'.encoding.should equal(Encoding::ISO_8859_1)
+ it "sets an empty result to the encoding of the source String" do
+ "abc".force_encoding(Encoding::ISO_8859_1) =~ /c/
+ $'.encoding.should equal(Encoding::ISO_8859_1)
+ end
end
end
@@ -190,9 +196,11 @@ describe "Predefined global $+" do
$+.should == 'a'
end
- it "sets the encoding to the encoding of the source String" do
- "abc".force_encoding(Encoding::EUC_JP) =~ /(b)/
- $+.encoding.should equal(Encoding::EUC_JP)
+ with_feature :encoding do
+ it "sets the encoding to the encoding of the source String" do
+ "abc".force_encoding(Encoding::EUC_JP) =~ /(b)/
+ $+.encoding.should equal(Encoding::EUC_JP)
+ end
end
end
@@ -217,9 +225,11 @@ describe "Predefined globals $1..N" do
test("-").should == nil
end
- it "sets the encoding to the encoding of the source String" do
- "abc".force_encoding(Encoding::EUC_JP) =~ /(b)/
- $1.encoding.should equal(Encoding::EUC_JP)
+ with_feature :encoding do
+ it "sets the encoding to the encoding of the source String" do
+ "abc".force_encoding(Encoding::EUC_JP) =~ /(b)/
+ $1.encoding.should equal(Encoding::EUC_JP)
+ end
end
end
@@ -233,12 +243,12 @@ describe "Predefined global $stdout" do
end
it "raises TypeError error if assigned to nil" do
- -> { $stdout = nil }.should raise_error(TypeError)
+ lambda { $stdout = nil }.should raise_error(TypeError)
end
it "raises TypeError error if assigned to object that doesn't respond to #write" do
obj = mock('object')
- -> { $stdout = obj }.should raise_error(TypeError)
+ lambda { $stdout = obj }.should raise_error(TypeError)
obj.stub!(:write)
$stdout = obj
@@ -562,15 +572,15 @@ describe "Predefined global $/" do
obj = mock("$/ value")
obj.should_not_receive(:to_str)
- -> { $/ = obj }.should raise_error(TypeError)
+ lambda { $/ = obj }.should raise_error(TypeError)
end
it "raises a TypeError if assigned a Fixnum" do
- -> { $/ = 1 }.should raise_error(TypeError)
+ lambda { $/ = 1 }.should raise_error(TypeError)
end
it "raises a TypeError if assigned a boolean" do
- -> { $/ = true }.should raise_error(TypeError)
+ lambda { $/ = true }.should raise_error(TypeError)
end
end
@@ -609,15 +619,15 @@ describe "Predefined global $-0" do
obj = mock("$-0 value")
obj.should_not_receive(:to_str)
- -> { $-0 = obj }.should raise_error(TypeError)
+ lambda { $-0 = obj }.should raise_error(TypeError)
end
it "raises a TypeError if assigned a Fixnum" do
- -> { $-0 = 1 }.should raise_error(TypeError)
+ lambda { $-0 = 1 }.should raise_error(TypeError)
end
it "raises a TypeError if assigned a boolean" do
- -> { $-0 = true }.should raise_error(TypeError)
+ lambda { $-0 = true }.should raise_error(TypeError)
end
end
@@ -631,34 +641,7 @@ describe "Predefined global $," do
end
it "raises TypeError if assigned a non-String" do
- -> { $, = Object.new }.should raise_error(TypeError)
- end
-end
-
-describe "Predefined global $." do
- it "can be assigned an Integer" do
- $. = 123
- $..should == 123
- end
-
- it "can be assigned a Float" do
- $. = 123.5
- $..should == 123
- end
-
- it "should call #to_int to convert the object to an Integer" do
- obj = mock("good-value")
- obj.should_receive(:to_int).and_return(321)
-
- $. = obj
- $..should == 321
- end
-
- it "raises TypeError if object can't be converted to an Integer" do
- obj = mock("bad-value")
- obj.should_receive(:to_int).and_return('abc')
-
- -> { $. = obj }.should raise_error(TypeError)
+ lambda { $, = Object.new }.should raise_error(TypeError)
end
end
@@ -771,6 +754,8 @@ __LINE__ String The current line number in the source file. [r/
$LOAD_PATH Array A synonym for $:. [r/o]
$-p Object Set to true if the -p option (which puts an implicit while gets . . . end
loop around your program) is present on the command line. [r/o]
+$SAFE Fixnum The current safe level. This variable’s value may never be
+ reduced by assignment. [thread] (Not implemented in Rubinius)
$VERBOSE Object Set to true if the -v, --version, -W, or -w option is specified on the com-
mand line. Set to false if no option, or -W1 is given. Set to nil if -W0
was specified. Setting this option to true causes the interpreter and some
@@ -800,15 +785,15 @@ describe "Execution variable $:" do
end
it "is read-only" do
- -> {
+ lambda {
$: = []
}.should raise_error(NameError)
- -> {
+ lambda {
$LOAD_PATH = []
}.should raise_error(NameError)
- -> {
+ lambda {
$-I = []
}.should raise_error(NameError)
end
@@ -816,15 +801,15 @@ end
describe "Global variable $\"" do
it "is an alias for $LOADED_FEATURES" do
- $".should equal $LOADED_FEATURES
+ $".object_id.should == $LOADED_FEATURES.object_id
end
it "is read-only" do
- -> {
+ lambda {
$" = []
}.should raise_error(NameError)
- -> {
+ lambda {
$LOADED_FEATURES = []
}.should raise_error(NameError)
end
@@ -832,7 +817,7 @@ end
describe "Global variable $<" do
it "is read-only" do
- -> {
+ lambda {
$< = nil
}.should raise_error(NameError)
end
@@ -840,7 +825,7 @@ end
describe "Global variable $FILENAME" do
it "is read-only" do
- -> {
+ lambda {
$FILENAME = "-"
}.should raise_error(NameError)
end
@@ -848,7 +833,7 @@ end
describe "Global variable $?" do
it "is read-only" do
- -> {
+ lambda {
$? = nil
}.should raise_error(NameError)
end
@@ -861,19 +846,19 @@ end
describe "Global variable $-a" do
it "is read-only" do
- -> { $-a = true }.should raise_error(NameError)
+ lambda { $-a = true }.should raise_error(NameError)
end
end
describe "Global variable $-l" do
it "is read-only" do
- -> { $-l = true }.should raise_error(NameError)
+ lambda { $-l = true }.should raise_error(NameError)
end
end
describe "Global variable $-p" do
it "is read-only" do
- -> { $-p = true }.should raise_error(NameError)
+ lambda { $-p = true }.should raise_error(NameError)
end
end
@@ -972,7 +957,7 @@ describe "Global variable $0" do
end
it "raises a TypeError when not given an object that can be coerced to a String" do
- -> { $0 = nil }.should raise_error(TypeError)
+ lambda { $0 = nil }.should raise_error(TypeError)
end
end
@@ -1014,7 +999,7 @@ describe "The predefined standard object nil" do
end
it "raises a SyntaxError if assigned to" do
- -> { eval("nil = true") }.should raise_error(SyntaxError)
+ lambda { eval("nil = true") }.should raise_error(SyntaxError)
end
end
@@ -1024,7 +1009,7 @@ describe "The predefined standard object true" do
end
it "raises a SyntaxError if assigned to" do
- -> { eval("true = false") }.should raise_error(SyntaxError)
+ lambda { eval("true = false") }.should raise_error(SyntaxError)
end
end
@@ -1034,13 +1019,13 @@ describe "The predefined standard object false" do
end
it "raises a SyntaxError if assigned to" do
- -> { eval("false = nil") }.should raise_error(SyntaxError)
+ lambda { eval("false = nil") }.should raise_error(SyntaxError)
end
end
describe "The self pseudo-variable" do
it "raises a SyntaxError if assigned to" do
- -> { eval("self = 1") }.should raise_error(SyntaxError)
+ lambda { eval("self = 1") }.should raise_error(SyntaxError)
end
end
@@ -1076,33 +1061,44 @@ TRUE TrueClass Synonym for true.
=end
describe "The predefined global constants" do
- before :each do
- @deprecated = Warning[:deprecated]
- Warning[:deprecated] = true
- end
- after :each do
- Warning[:deprecated] = @deprecated
- end
-
- it "includes TRUE" do
- Object.const_defined?(:TRUE).should == true
- -> {
+ ruby_version_is ""..."2.4" do
+ it "includes TRUE" do
+ Object.const_defined?(:TRUE).should == true
TRUE.should equal(true)
- }.should complain(/constant ::TRUE is deprecated/)
- end
+ end
- it "includes FALSE" do
- Object.const_defined?(:FALSE).should == true
- -> {
+ it "includes FALSE" do
+ Object.const_defined?(:FALSE).should == true
FALSE.should equal(false)
- }.should complain(/constant ::FALSE is deprecated/)
- end
+ end
- it "includes NIL" do
- Object.const_defined?(:NIL).should == true
- -> {
+ it "includes NIL" do
+ Object.const_defined?(:NIL).should == true
NIL.should equal(nil)
- }.should complain(/constant ::NIL is deprecated/)
+ end
+ end
+
+ ruby_version_is "2.4" do
+ it "includes TRUE" do
+ Object.const_defined?(:TRUE).should == true
+ -> {
+ TRUE.should equal(true)
+ }.should complain(/constant ::TRUE is deprecated/)
+ end
+
+ it "includes FALSE" do
+ Object.const_defined?(:FALSE).should == true
+ -> {
+ FALSE.should equal(false)
+ }.should complain(/constant ::FALSE is deprecated/)
+ end
+
+ it "includes NIL" do
+ Object.const_defined?(:NIL).should == true
+ -> {
+ NIL.should equal(nil)
+ }.should complain(/constant ::NIL is deprecated/)
+ end
end
it "includes STDIN" do
@@ -1135,108 +1131,110 @@ describe "The predefined global constants" do
end
-describe "The predefined global constant" do
- before :each do
- @external = Encoding.default_external
- @internal = Encoding.default_internal
- end
-
- after :each do
- Encoding.default_external = @external
- Encoding.default_internal = @internal
- end
-
- describe "STDIN" do
- it "has the same external encoding as Encoding.default_external" do
- STDIN.external_encoding.should equal(Encoding.default_external)
+with_feature :encoding do
+ describe "The predefined global constant" do
+ before :each do
+ @external = Encoding.default_external
+ @internal = Encoding.default_internal
end
- it "has the same external encoding as Encoding.default_external when that encoding is changed" do
- Encoding.default_external = Encoding::ISO_8859_16
- STDIN.external_encoding.should equal(Encoding::ISO_8859_16)
+ after :each do
+ Encoding.default_external = @external
+ Encoding.default_internal = @internal
end
- it "has the encodings set by #set_encoding" do
- code = "STDIN.set_encoding Encoding::IBM775, Encoding::IBM866; " \
- "p [STDIN.external_encoding.name, STDIN.internal_encoding.name]"
- ruby_exe(code).chomp.should == %{["IBM775", "IBM866"]}
- end
+ describe "STDIN" do
+ it "has the same external encoding as Encoding.default_external" do
+ STDIN.external_encoding.should equal(Encoding.default_external)
+ end
- it "retains the encoding set by #set_encoding when Encoding.default_external is changed" do
- code = "STDIN.set_encoding Encoding::IBM775, Encoding::IBM866; " \
- "Encoding.default_external = Encoding::ISO_8859_16;" \
- "p [STDIN.external_encoding.name, STDIN.internal_encoding.name]"
- ruby_exe(code).chomp.should == %{["IBM775", "IBM866"]}
- end
+ it "has the same external encoding as Encoding.default_external when that encoding is changed" do
+ Encoding.default_external = Encoding::ISO_8859_16
+ STDIN.external_encoding.should equal(Encoding::ISO_8859_16)
+ end
- it "has nil for the internal encoding" do
- STDIN.internal_encoding.should be_nil
- end
+ it "has the encodings set by #set_encoding" do
+ code = "STDIN.set_encoding Encoding::IBM775, Encoding::IBM866; " \
+ "p [STDIN.external_encoding.name, STDIN.internal_encoding.name]"
+ ruby_exe(code).chomp.should == %{["IBM775", "IBM866"]}
+ end
- it "has nil for the internal encoding despite Encoding.default_internal being changed" do
- Encoding.default_internal = Encoding::IBM437
- STDIN.internal_encoding.should be_nil
- end
- end
+ it "retains the encoding set by #set_encoding when Encoding.default_external is changed" do
+ code = "STDIN.set_encoding Encoding::IBM775, Encoding::IBM866; " \
+ "Encoding.default_external = Encoding::ISO_8859_16;" \
+ "p [STDIN.external_encoding.name, STDIN.internal_encoding.name]"
+ ruby_exe(code).chomp.should == %{["IBM775", "IBM866"]}
+ end
- describe "STDOUT" do
- it "has nil for the external encoding" do
- STDOUT.external_encoding.should be_nil
- end
+ it "has nil for the internal encoding" do
+ STDIN.internal_encoding.should be_nil
+ end
- it "has nil for the external encoding despite Encoding.default_external being changed" do
- Encoding.default_external = Encoding::ISO_8859_1
- STDOUT.external_encoding.should be_nil
+ it "has nil for the internal encoding despite Encoding.default_internal being changed" do
+ Encoding.default_internal = Encoding::IBM437
+ STDIN.internal_encoding.should be_nil
+ end
end
- it "has the encodings set by #set_encoding" do
- code = "STDOUT.set_encoding Encoding::IBM775, Encoding::IBM866; " \
- "p [STDOUT.external_encoding.name, STDOUT.internal_encoding.name]"
- ruby_exe(code).chomp.should == %{["IBM775", "IBM866"]}
- end
+ describe "STDOUT" do
+ it "has nil for the external encoding" do
+ STDOUT.external_encoding.should be_nil
+ end
- it "has nil for the internal encoding" do
- STDOUT.internal_encoding.should be_nil
- end
+ it "has nil for the external encoding despite Encoding.default_external being changed" do
+ Encoding.default_external = Encoding::ISO_8859_1
+ STDOUT.external_encoding.should be_nil
+ end
- it "has nil for the internal encoding despite Encoding.default_internal being changed" do
- Encoding.default_internal = Encoding::IBM437
- STDOUT.internal_encoding.should be_nil
- end
- end
+ it "has the encodings set by #set_encoding" do
+ code = "STDOUT.set_encoding Encoding::IBM775, Encoding::IBM866; " \
+ "p [STDOUT.external_encoding.name, STDOUT.internal_encoding.name]"
+ ruby_exe(code).chomp.should == %{["IBM775", "IBM866"]}
+ end
- describe "STDERR" do
- it "has nil for the external encoding" do
- STDERR.external_encoding.should be_nil
- end
+ it "has nil for the internal encoding" do
+ STDOUT.internal_encoding.should be_nil
+ end
- it "has nil for the external encoding despite Encoding.default_external being changed" do
- Encoding.default_external = Encoding::ISO_8859_1
- STDERR.external_encoding.should be_nil
+ it "has nil for the internal encoding despite Encoding.default_internal being changed" do
+ Encoding.default_internal = Encoding::IBM437
+ STDOUT.internal_encoding.should be_nil
+ end
end
- it "has the encodings set by #set_encoding" do
- code = "STDERR.set_encoding Encoding::IBM775, Encoding::IBM866; " \
- "p [STDERR.external_encoding.name, STDERR.internal_encoding.name]"
- ruby_exe(code).chomp.should == %{["IBM775", "IBM866"]}
- end
+ describe "STDERR" do
+ it "has nil for the external encoding" do
+ STDERR.external_encoding.should be_nil
+ end
- it "has nil for the internal encoding" do
- STDERR.internal_encoding.should be_nil
- end
+ it "has nil for the external encoding despite Encoding.default_external being changed" do
+ Encoding.default_external = Encoding::ISO_8859_1
+ STDERR.external_encoding.should be_nil
+ end
- it "has nil for the internal encoding despite Encoding.default_internal being changed" do
- Encoding.default_internal = Encoding::IBM437
- STDERR.internal_encoding.should be_nil
+ it "has the encodings set by #set_encoding" do
+ code = "STDERR.set_encoding Encoding::IBM775, Encoding::IBM866; " \
+ "p [STDERR.external_encoding.name, STDERR.internal_encoding.name]"
+ ruby_exe(code).chomp.should == %{["IBM775", "IBM866"]}
+ end
+
+ it "has nil for the internal encoding" do
+ STDERR.internal_encoding.should be_nil
+ end
+
+ it "has nil for the internal encoding despite Encoding.default_internal being changed" do
+ Encoding.default_internal = Encoding::IBM437
+ STDERR.internal_encoding.should be_nil
+ end
end
- end
- describe "ARGV" do
- it "contains Strings encoded in locale Encoding" do
- code = fixture __FILE__, "argv_encoding.rb"
- result = ruby_exe(code, args: "a b")
- encoding = Encoding.default_external
- result.chomp.should == %{["#{encoding}", "#{encoding}"]}
+ describe "ARGV" do
+ it "contains Strings encoded in locale Encoding" do
+ code = fixture __FILE__, "argv_encoding.rb"
+ result = ruby_exe(code, args: "a b")
+ encoding = Encoding.default_external
+ result.chomp.should == %{["#{encoding}", "#{encoding}"]}
+ end
end
end
end
diff --git a/spec/ruby/language/private_spec.rb b/spec/ruby/language/private_spec.rb
index ddf185e6d2..796c0c1711 100644
--- a/spec/ruby/language/private_spec.rb
+++ b/spec/ruby/language/private_spec.rb
@@ -1,15 +1,15 @@
-require_relative '../spec_helper'
-require_relative 'fixtures/private'
+require File.expand_path('../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/private', __FILE__)
describe "The private keyword" do
it "marks following methods as being private" do
a = Private::A.new
a.methods.should_not include(:bar)
- -> { a.bar }.should raise_error(NoMethodError)
+ lambda { a.bar }.should raise_error(NoMethodError)
b = Private::B.new
b.methods.should_not include(:bar)
- -> { b.bar }.should raise_error(NoMethodError)
+ lambda { b.bar }.should raise_error(NoMethodError)
end
# def expr.meth() methods are always public
@@ -22,7 +22,7 @@ describe "The private keyword" do
c.methods.should include(:baz)
c.baz
Private::B.public_class_method1.should == 1
- -> { Private::B.private_class_method1 }.should raise_error(NoMethodError)
+ lambda { Private::B.private_class_method1 }.should raise_error(NoMethodError)
end
it "is no longer in effect when the class is closed" do
@@ -42,12 +42,12 @@ describe "The private keyword" do
klass.class_eval do
private :foo
end
- -> { f.foo }.should raise_error(NoMethodError)
+ lambda { f.foo }.should raise_error(NoMethodError)
end
- it "changes visibility of previously called methods with same send/call site" do
+ it "changes visiblity of previously called methods with same send/call site" do
g = ::Private::G.new
- -> {
+ lambda {
2.times do
g.foo
module ::Private
@@ -61,7 +61,7 @@ describe "The private keyword" do
it "changes the visibility of the existing method in the subclass" do
::Private::A.new.foo.should == 'foo'
- -> { ::Private::H.new.foo }.should raise_error(NoMethodError)
+ lambda {::Private::H.new.foo}.should raise_error(NoMethodError)
::Private::H.new.send(:foo).should == 'foo'
end
end
diff --git a/spec/ruby/language/proc_spec.rb b/spec/ruby/language/proc_spec.rb
index c44e711d2b..bbef318826 100644
--- a/spec/ruby/language/proc_spec.rb
+++ b/spec/ruby/language/proc_spec.rb
@@ -1,4 +1,4 @@
-require_relative '../spec_helper'
+require File.expand_path('../../spec_helper', __FILE__)
describe "A Proc" do
it "captures locals from the surrounding scope" do
@@ -21,7 +21,7 @@ describe "A Proc" do
@l.call.should == 1
end
- it "raises an ArgumentError if a value is passed" do
+ it "raises an ArgumentErro if a value is passed" do
lambda { @l.call(0) }.should raise_error(ArgumentError)
end
end
diff --git a/spec/ruby/language/range_spec.rb b/spec/ruby/language/range_spec.rb
deleted file mode 100644
index c720c5b98e..0000000000
--- a/spec/ruby/language/range_spec.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-require_relative '../spec_helper'
-require_relative 'fixtures/classes'
-
-describe "Literal Ranges" do
- it "creates range object" do
- (1..10).should == Range.new(1, 10)
- end
-
- it "creates range with excluded right boundary" do
- (1...10).should == Range.new(1, 10, true)
- end
-
- ruby_version_is "2.6" do
- it "creates endless ranges" do
- eval("(1..)").should == Range.new(1, nil)
- eval("(1...)").should == Range.new(1, nil, true)
- end
- end
-end
diff --git a/spec/ruby/language/redo_spec.rb b/spec/ruby/language/redo_spec.rb
index 57532553b3..53fd30b4f2 100644
--- a/spec/ruby/language/redo_spec.rb
+++ b/spec/ruby/language/redo_spec.rb
@@ -1,9 +1,9 @@
-require_relative '../spec_helper'
+require File.expand_path('../../spec_helper', __FILE__)
describe "The redo statement" do
it "restarts block execution if used within block" do
a = []
- -> {
+ lambda {
a << 1
redo if a.size < 2
a << 2
@@ -58,7 +58,7 @@ describe "The redo statement" do
describe "in a method" do
it "is invalid and raises a SyntaxError" do
- -> {
+ lambda {
eval("def m; redo; end")
}.should raise_error(SyntaxError)
end
diff --git a/spec/ruby/language/regexp/anchors_spec.rb b/spec/ruby/language/regexp/anchors_spec.rb
index 0129e255da..c6a620a221 100644
--- a/spec/ruby/language/regexp/anchors_spec.rb
+++ b/spec/ruby/language/regexp/anchors_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
describe "Regexps with anchors" do
it "supports ^ (line start anchor)" do
diff --git a/spec/ruby/language/regexp/back-references_spec.rb b/spec/ruby/language/regexp/back-references_spec.rb
index 81015ac21e..607f4463fd 100644
--- a/spec/ruby/language/regexp/back-references_spec.rb
+++ b/spec/ruby/language/regexp/back-references_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
describe "Regexps with back-references" do
it "saves match data in the $~ pseudo-global variable" do
@@ -7,7 +7,7 @@ describe "Regexps with back-references" do
$~.to_a.should == ["ll"]
end
- it "saves captures in numbered $[1-N] variables" do
+ it "saves captures in numbered $[1-9] variables" do
"1234567890" =~ /(1)(2)(3)(4)(5)(6)(7)(8)(9)(0)/
$~.to_a.should == ["1234567890", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]
$1.should == "1"
@@ -19,7 +19,6 @@ describe "Regexps with back-references" do
$7.should == "7"
$8.should == "8"
$9.should == "9"
- $10.should == "0"
end
it "will not clobber capture variables across threads" do
@@ -46,8 +45,4 @@ describe "Regexps with back-references" do
it "resets nested \<n> backreference before match of outer subexpression" do
/(a\1?){2}/.match("aaaa").to_a.should == ["aa", "a"]
end
-
- it "can match an optional quote, followed by content, followed by a matching quote, as the whole string" do
- /^("|)(.*)\1$/.match('x').to_a.should == ["x", "", "x"]
- end
end
diff --git a/spec/ruby/language/regexp/character_classes_spec.rb b/spec/ruby/language/regexp/character_classes_spec.rb
index 5f4221e213..ce66d8e65f 100644
--- a/spec/ruby/language/regexp/character_classes_spec.rb
+++ b/spec/ruby/language/regexp/character_classes_spec.rb
@@ -1,6 +1,6 @@
# coding: utf-8
-require_relative '../../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
describe "Regexp with character classes" do
it "supports \\w (word character)" do
@@ -89,7 +89,7 @@ describe "Regexp with character classes" do
/[^[:lower:]A-C]+/.match("abcABCDEF123def").to_a.should == ["DEF123"] # negated character class
/[:alnum:]+/.match("a:l:n:u:m").to_a.should == ["a:l:n:u:m"] # should behave like regular character class composed of the individual letters
/[\[:alnum:]+/.match("[:a:l:n:u:m").to_a.should == ["[:a:l:n:u:m"] # should behave like regular character class composed of the individual letters
- -> { eval('/[[:alpha:]-[:digit:]]/') }.should raise_error(SyntaxError) # can't use character class as a start value of range
+ lambda { eval('/[[:alpha:]-[:digit:]]/') }.should raise_error(SyntaxError) # can't use character class as a start value of range
end
it "matches ASCII characters with [[:ascii:]]" do
@@ -609,23 +609,25 @@ describe "Regexp with character classes" do
"루비(Ruby)".match(/\p{Hangul}+/u).to_a.should == ["루비"]
end
- it "supports \\X (unicode 9.0 with UTR #51 workarounds)" do
- # simple emoji without any fancy modifier or ZWJ
- /\X/.match("\u{1F98A}").to_a.should == ["🦊"]
+ ruby_version_is "2.4" do
+ it "supports \\X (unicode 9.0 with UTR #51 workarounds)" do
+ # simple emoji without any fancy modifier or ZWJ
+ /\X/.match("\u{1F98A}").to_a.should == ["🦊"]
- # skin tone modifier
- /\X/.match("\u{1F918}\u{1F3FD}").to_a.should == ["🤘ðŸ½"]
+ # skin tone modifier
+ /\X/.match("\u{1F918}\u{1F3FD}").to_a.should == ["🤘ðŸ½"]
- # emoji joined with ZWJ
- /\X/.match("\u{1F3F3}\u{FE0F}\u{200D}\u{1F308}").to_a.should == ["ðŸ³ï¸â€ðŸŒˆ"]
- /\X/.match("\u{1F469}\u{200D}\u{1F469}\u{200D}\u{1F467}\u{200D}\u{1F466}").to_a.should == ["👩â€ðŸ‘©â€ðŸ‘§â€ðŸ‘¦"]
+ # emoji joined with ZWJ
+ /\X/.match("\u{1F3F3}\u{FE0F}\u{200D}\u{1F308}").to_a.should == ["ðŸ³ï¸â€ðŸŒˆ"]
+ /\X/.match("\u{1F469}\u{200D}\u{1F469}\u{200D}\u{1F467}\u{200D}\u{1F466}").to_a.should == ["👩â€ðŸ‘©â€ðŸ‘§â€ðŸ‘¦"]
- # without the ZWJ
- /\X+/.match("\u{1F3F3}\u{FE0F}\u{1F308}").to_a.should == ["ðŸ³ï¸ðŸŒˆ"]
- /\X+/.match("\u{1F469}\u{1F469}\u{1F467}\u{1F466}").to_a.should == ["👩👩👧👦"]
+ # without the ZWJ
+ /\X+/.match("\u{1F3F3}\u{FE0F}\u{1F308}").to_a.should == ["ðŸ³ï¸ðŸŒˆ"]
+ /\X+/.match("\u{1F469}\u{1F469}\u{1F467}\u{1F466}").to_a.should == ["👩👩👧👦"]
- # both of the ZWJ combined
- /\X+/.match("\u{1F3F3}\u{FE0F}\u{200D}\u{1F308}\u{1F469}\u{200D}\u{1F469}\u{200D}\u{1F467}\u{200D}\u{1F466}")
- .to_a.should == ["ðŸ³ï¸â€ðŸŒˆðŸ‘©â€ðŸ‘©â€ðŸ‘§â€ðŸ‘¦"]
+ # both of the ZWJ combined
+ /\X+/.match("\u{1F3F3}\u{FE0F}\u{200D}\u{1F308}\u{1F469}\u{200D}\u{1F469}\u{200D}\u{1F467}\u{200D}\u{1F466}")
+ .to_a.should == ["ðŸ³ï¸â€ðŸŒˆðŸ‘©â€ðŸ‘©â€ðŸ‘§â€ðŸ‘¦"]
+ end
end
end
diff --git a/spec/ruby/language/regexp/encoding_spec.rb b/spec/ruby/language/regexp/encoding_spec.rb
index b8559c6b27..1f62244a28 100644
--- a/spec/ruby/language/regexp/encoding_spec.rb
+++ b/spec/ruby/language/regexp/encoding_spec.rb
@@ -1,6 +1,6 @@
# -*- encoding: binary -*-
-require_relative '../../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
describe "Regexps with encoding modifiers" do
it "supports /e (EUC encoding)" do
@@ -42,20 +42,16 @@ describe "Regexps with encoding modifiers" do
/./n.encoding.should == Encoding::US_ASCII
end
- it 'uses BINARY when is not initialized' do
- Regexp.allocate.encoding.should == Encoding::BINARY
- end
-
- it 'uses BINARY as /n encoding if not all chars are 7-bit' do
- /\xFF/n.encoding.should == Encoding::BINARY
+ it 'uses ASCII-8BIT as /n encoding if not all chars are 7-bit' do
+ /\xFF/n.encoding.should == Encoding::ASCII_8BIT
end
it 'preserves US-ASCII as /n encoding through interpolation if all chars are 7-bit' do
/.#{/./}/n.encoding.should == Encoding::US_ASCII
end
- it 'preserves BINARY as /n encoding through interpolation if all chars are 7-bit' do
- /\xFF#{/./}/n.encoding.should == Encoding::BINARY
+ it 'preserves ASCII-8BIT as /n encoding through interpolation if all chars are 7-bit' do
+ /\xFF#{/./}/n.encoding.should == Encoding::ASCII_8BIT
end
it "supports /s (Windows_31J encoding)" do
@@ -104,16 +100,4 @@ describe "Regexps with encoding modifiers" do
it "selects last of multiple encoding specifiers" do
/foo/ensuensuens.should == /foo/s
end
-
- it "raises Encoding::CompatibilityError when trying match against different encodings" do
- -> { /\A[[:space:]]*\z/.match(" ".encode("UTF-16LE")) }.should raise_error(Encoding::CompatibilityError)
- end
-
- it "raises Encoding::CompatibilityError when trying match? against different encodings" do
- -> { /\A[[:space:]]*\z/.match?(" ".encode("UTF-16LE")) }.should raise_error(Encoding::CompatibilityError)
- end
-
- it "raises Encoding::CompatibilityError when trying =~ against different encodings" do
- -> { /\A[[:space:]]*\z/ =~ " ".encode("UTF-16LE") }.should raise_error(Encoding::CompatibilityError)
- end
end
diff --git a/spec/ruby/language/regexp/escapes_spec.rb b/spec/ruby/language/regexp/escapes_spec.rb
index 14e1424d47..50ac22e51e 100644
--- a/spec/ruby/language/regexp/escapes_spec.rb
+++ b/spec/ruby/language/regexp/escapes_spec.rb
@@ -1,6 +1,6 @@
# -*- encoding: binary -*-
-require_relative '../../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
describe "Regexps with escape characters" do
it "they're supported" do
@@ -48,7 +48,7 @@ describe "Regexps with escape characters" do
/\x0AA/.match("\nA").to_a.should == ["\nA"]
/\xAG/.match("\nG").to_a.should == ["\nG"]
# Non-matches
- -> { eval('/\xG/') }.should raise_error(SyntaxError)
+ lambda { eval('/\xG/') }.should raise_error(SyntaxError)
# \x{7HHHHHHH} wide hexadecimal char (character code point value)
end
@@ -67,11 +67,11 @@ describe "Regexps with escape characters" do
/\cJ/.match("\r").should be_nil
# Parsing precedence
- /\cJ+/.match("\n\n").to_a.should == ["\n\n"] # Quantifiers apply to entire escape sequence
+ /\cJ+/.match("\n\n").to_a.should == ["\n\n"] # Quantifers apply to entire escape sequence
/\\cJ/.match("\\cJ").to_a.should == ["\\cJ"]
- -> { eval('/[abc\x]/') }.should raise_error(SyntaxError) # \x is treated as a escape sequence even inside a character class
+ lambda { eval('/[abc\x]/') }.should raise_error(SyntaxError) # \x is treated as a escape sequence even inside a character class
# Syntax error
- -> { eval('/\c/') }.should raise_error(SyntaxError)
+ lambda { eval('/\c/') }.should raise_error(SyntaxError)
# \cx control char (character code point value)
# \C-x control char (character code point value)
diff --git a/spec/ruby/language/regexp/grouping_spec.rb b/spec/ruby/language/regexp/grouping_spec.rb
index 8806d06746..443cab7ee0 100644
--- a/spec/ruby/language/regexp/grouping_spec.rb
+++ b/spec/ruby/language/regexp/grouping_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
describe "Regexps with grouping" do
it "support ()" do
@@ -12,7 +12,7 @@ describe "Regexps with grouping" do
end
it "raises a SyntaxError when parentheses aren't balanced" do
- -> { eval "/(hay(st)ack/" }.should raise_error(SyntaxError)
+ lambda { eval "/(hay(st)ack/" }.should raise_error(SyntaxError)
end
it "supports (?: ) (non-capturing group)" do
diff --git a/spec/ruby/language/regexp/interpolation_spec.rb b/spec/ruby/language/regexp/interpolation_spec.rb
index ed0b724763..5536c718f1 100644
--- a/spec/ruby/language/regexp/interpolation_spec.rb
+++ b/spec/ruby/language/regexp/interpolation_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
describe "Regexps with interpolation" do
@@ -41,9 +41,9 @@ describe "Regexps with interpolation" do
it "throws RegexpError for malformed interpolation" do
s = ""
- -> { /(#{s}/ }.should raise_error(RegexpError)
+ lambda { /(#{s}/ }.should raise_error(RegexpError)
s = "("
- -> { /#{s}/ }.should raise_error(RegexpError)
+ lambda { /#{s}/ }.should raise_error(RegexpError)
end
it "allows interpolation in extended mode" do
diff --git a/spec/ruby/language/regexp/modifiers_spec.rb b/spec/ruby/language/regexp/modifiers_spec.rb
index 2f5522bc8a..a7052a941c 100644
--- a/spec/ruby/language/regexp/modifiers_spec.rb
+++ b/spec/ruby/language/regexp/modifiers_spec.rb
@@ -1,7 +1,7 @@
-require_relative '../../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
-describe "Regexps with modifiers" do
+describe "Regexps with modifers" do
it "supports /i (case-insensitive)" do
/foo/i.match("FOO").to_a.should == ["FOO"]
end
@@ -36,12 +36,14 @@ describe "Regexps with modifiers" do
/foo/imox.match("foo").to_a.should == ["foo"]
/foo/imoximox.match("foo").to_a.should == ["foo"]
- -> { eval('/foo/a') }.should raise_error(SyntaxError)
+ lambda { eval('/foo/a') }.should raise_error(SyntaxError)
end
- it "supports (?~) (absent operator)" do
- Regexp.new("(?~foo)").match("hello").to_a.should == ["hello"]
- "foo".scan(Regexp.new("(?~foo)")).should == ["fo","o",""]
+ ruby_version_is "2.4" do
+ it "supports (?~) (absent operator)" do
+ Regexp.new("(?~foo)").match("hello").to_a.should == ["hello"]
+ "foo".scan(Regexp.new("(?~foo)")).should == ["fo","o",""]
+ end
end
it "supports (?imx-imx) (inline modifiers)" do
@@ -76,7 +78,7 @@ describe "Regexps with modifiers" do
/(?i-i)foo/.match("FOO").should be_nil
/(?ii)foo/.match("FOO").to_a.should == ["FOO"]
/(?-)foo/.match("foo").to_a.should == ["foo"]
- -> { eval('/(?o)/') }.should raise_error(SyntaxError)
+ lambda { eval('/(?o)/') }.should raise_error(SyntaxError)
end
it "supports (?imx-imx:expr) (scoped inline modifiers)" do
@@ -96,7 +98,7 @@ describe "Regexps with modifiers" do
/(?i-i:foo)/.match("FOO").should be_nil
/(?ii:foo)/.match("FOO").to_a.should == ["FOO"]
/(?-:)foo/.match("foo").to_a.should == ["foo"]
- -> { eval('/(?o:)/') }.should raise_error(SyntaxError)
+ lambda { eval('/(?o:)/') }.should raise_error(SyntaxError)
end
it "supports . with /m" do
@@ -104,7 +106,7 @@ describe "Regexps with modifiers" do
/./m.match("\n").to_a.should == ["\n"]
end
- it "supports ASCII/Unicode modifiers" do
+ it "supports ASII/Unicode modifiers" do
eval('/(?a)[[:alpha:]]+/').match("a\u3042").to_a.should == ["a"]
eval('/(?d)[[:alpha:]]+/').match("a\u3042").to_a.should == ["a\u3042"]
eval('/(?u)[[:alpha:]]+/').match("a\u3042").to_a.should == ["a\u3042"]
diff --git a/spec/ruby/language/regexp/repetition_spec.rb b/spec/ruby/language/regexp/repetition_spec.rb
index 7bb767ccaf..2fc8a74a47 100644
--- a/spec/ruby/language/regexp/repetition_spec.rb
+++ b/spec/ruby/language/regexp/repetition_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
describe "Regexps with repetition" do
it "supports * (0 or more of previous subexpression)" do
@@ -34,11 +34,20 @@ describe "Regexps with repetition" do
/.([0-9]){3,5}?foo/.match("9876543210foo").to_a.should == ["543210foo", "0"]
end
- it "does not treat {m,n}+ as possessive" do
- -> {
+ ruby_version_is ""..."2.4" do
+ it "does not treat {m,n}+ as possessive" do
@regexp = eval "/foo(A{0,1}+)Abar/"
- }.should complain(/nested repeat operator/)
- @regexp.match("fooAAAbar").to_a.should == ["fooAAAbar", "AA"]
+ @regexp.match("fooAAAbar").to_a.should == ["fooAAAbar", "AA"]
+ end
+ end
+
+ ruby_version_is "2.4" do
+ it "does not treat {m,n}+ as possessive" do
+ -> {
+ @regexp = eval "/foo(A{0,1}+)Abar/"
+ }.should complain(/nested repeat operato/)
+ @regexp.match("fooAAAbar").to_a.should == ["fooAAAbar", "AA"]
+ end
end
it "supports ? (0 or 1 of previous subexpression)" do
diff --git a/spec/ruby/language/regexp_spec.rb b/spec/ruby/language/regexp_spec.rb
index 67c7c034e9..d4b0c81128 100644
--- a/spec/ruby/language/regexp_spec.rb
+++ b/spec/ruby/language/regexp_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../spec_helper'
-require_relative 'fixtures/classes'
+require File.expand_path('../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
describe "Literal Regexps" do
it "matches against $_ (last input) in a conditional if no explicit matchee provided" do
@@ -27,7 +27,7 @@ describe "Literal Regexps" do
end
it "throws SyntaxError for malformed literals" do
- -> { eval('/(/') }.should raise_error(SyntaxError)
+ lambda { eval('/(/') }.should raise_error(SyntaxError)
end
#############################################################################
@@ -54,7 +54,7 @@ describe "Literal Regexps" do
it "disallows first part of paired delimiters to be used as non-paired delimiters" do
LanguageSpecs.paired_delimiters.each do |p0, p1|
- -> { eval("%r#{p0} foo #{p0}") }.should raise_error(SyntaxError)
+ lambda { eval("%r#{p0} foo #{p0}") }.should raise_error(SyntaxError)
end
end
@@ -65,11 +65,11 @@ describe "Literal Regexps" do
end
it "disallows alphabets as non-paired delimiter with %r" do
- -> { eval('%ra foo a') }.should raise_error(SyntaxError)
+ lambda { eval('%ra foo a') }.should raise_error(SyntaxError)
end
it "disallows spaces after %r and delimiter" do
- -> { eval('%r !foo!') }.should raise_error(SyntaxError)
+ lambda { eval('%r !foo!') }.should raise_error(SyntaxError)
end
it "allows unescaped / to be used with %r" do
@@ -97,7 +97,7 @@ describe "Literal Regexps" do
it "supports (?> ) (embedded subexpression)" do
/(?>foo)(?>bar)/.match("foobar").to_a.should == ["foobar"]
- /(?>foo*)obar/.match("foooooooobar").should be_nil # it is possessive
+ /(?>foo*)obar/.match("foooooooobar").should be_nil # it is possesive
end
it "supports (?# )" do
@@ -147,31 +147,4 @@ describe "Literal Regexps" do
pattern.should_not =~ 'fooF'
pattern.should_not =~ 'T'
end
-
- escapable_terminators = ['!', '"', '#', '%', '&', "'", ',', '-', ':', ';', '@', '_', '`']
-
- it "supports escaping characters when used as a terminator" do
- escapable_terminators.each do |c|
- ref = "(?-mix:#{c})"
- pattern = eval("%r" + c + "\\" + c + c)
- pattern.to_s.should == ref
- end
- end
-
- it "treats an escaped non-escapable character normally when used as a terminator" do
- all_terminators = [*("!".."/"), *(":".."@"), *("[".."`"), *("{".."~")]
- special_cases = ['(', '{', '[', '<', '\\', '=', '~']
- (all_terminators - special_cases - escapable_terminators).each do |c|
- ref = "(?-mix:\\#{c})"
- pattern = eval("%r" + c + "\\" + c + c)
- pattern.to_s.should == ref
- end
- end
-
- it "support handling unicode 9.0 characters with POSIX bracket expressions" do
- char_lowercase = "\u{104D8}" # OSAGE SMALL LETTER A
- /[[:lower:]]/.match(char_lowercase).to_s.should == char_lowercase
- char_uppercase = "\u{104B0}" # OSAGE CAPITAL LETTER A
- /[[:upper:]]/.match(char_uppercase).to_s.should == char_uppercase
- end
end
diff --git a/spec/ruby/language/rescue_spec.rb b/spec/ruby/language/rescue_spec.rb
index a912e17431..0dc8894740 100644
--- a/spec/ruby/language/rescue_spec.rb
+++ b/spec/ruby/language/rescue_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../spec_helper'
-require_relative 'fixtures/rescue'
+require File.expand_path('../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/rescue', __FILE__)
class SpecificExampleException < StandardError
end
@@ -54,7 +54,7 @@ describe "The rescue keyword" do
end
it "can rescue multiple raised exceptions with a single rescue block" do
- [->{raise ArbitraryException}, ->{raise SpecificExampleException}].map do |block|
+ [lambda{raise ArbitraryException}, lambda{raise SpecificExampleException}].map do |block|
begin
block.call
rescue SpecificExampleException, ArbitraryException
@@ -72,7 +72,7 @@ describe "The rescue keyword" do
end
caught_it.should be_true
caught = []
- [->{raise ArbitraryException}, ->{raise SpecificExampleException}].each do |block|
+ [lambda{raise ArbitraryException}, lambda{raise SpecificExampleException}].each do |block|
begin
block.call
rescue *exception_list
@@ -94,7 +94,7 @@ describe "The rescue keyword" do
end
caught_it.should be_true
caught = []
- [->{raise ArbitraryException}, ->{raise SpecificExampleException}].each do |block|
+ [lambda{raise ArbitraryException}, lambda{raise SpecificExampleException}].each do |block|
begin
block.call
rescue ArbitraryException, *exception_list
@@ -108,7 +108,7 @@ describe "The rescue keyword" do
end
it "will only rescue the specified exceptions when doing a splat rescue" do
- -> do
+ lambda do
begin
raise OtherCustomException, "not rescued!"
rescue *exception_list
@@ -142,19 +142,6 @@ describe "The rescue keyword" do
ScratchPad.recorded.should == [:standard_error]
end
- it "rescues the exception in the deepest rescue block declared to handle the appropriate exception type" do
- begin
- begin
- RescueSpecs.raise_standard_error
- rescue ArgumentError
- end
- rescue StandardError => e
- e.backtrace.first.should include ":in `raise_standard_error'"
- else
- fail("exception wasn't handled by the correct rescue block")
- end
- end
-
it "will execute an else block only if no exceptions were raised" do
result = begin
ScratchPad << :one
@@ -208,34 +195,18 @@ describe "The rescue keyword" do
ScratchPad.recorded.should == [:one, :else_ran, :ensure_ran, :outside_begin]
end
- ruby_version_is ''...'2.6' do
- it "will execute an else block even without rescue and ensure" do
- -> {
- eval <<-ruby
- begin
- ScratchPad << :begin
- else
- ScratchPad << :else
- end
- ruby
- }.should complain(/else without rescue is useless/)
+ it "will execute an else block even without rescue and ensure" do
+ lambda {
+ eval <<-ruby
+ begin
+ ScratchPad << :begin
+ else
+ ScratchPad << :else
+ end
+ ruby
+ }.should complain(/else without rescue is useless/)
- ScratchPad.recorded.should == [:begin, :else]
- end
- end
-
- ruby_version_is '2.6' do
- it "raises SyntaxError when else is used without rescue and ensure" do
- -> {
- eval <<-ruby
- begin
- ScratchPad << :begin
- else
- ScratchPad << :else
- end
- ruby
- }.should raise_error(SyntaxError, /else without rescue is useless/)
- end
+ ScratchPad.recorded.should == [:begin, :else]
end
it "will not execute an else block if an exception was raised" do
@@ -294,7 +265,7 @@ describe "The rescue keyword" do
end
it "will not rescue errors raised in an else block in the rescue block above it" do
- -> do
+ lambda do
begin
ScratchPad << :one
rescue Exception
@@ -329,7 +300,7 @@ describe "The rescue keyword" do
[ Exception.new, NoMemoryError.new, ScriptError.new, SecurityError.new,
SignalException.new('INT'), SystemExit.new, SystemStackError.new
].each do |exception|
- -> {
+ lambda {
begin
raise exception
rescue
@@ -361,7 +332,7 @@ describe "The rescue keyword" do
it "only accepts Module or Class in rescue clauses" do
rescuer = 42
- -> {
+ lambda {
begin
raise "error"
rescue rescuer
@@ -373,7 +344,7 @@ describe "The rescue keyword" do
it "only accepts Module or Class in splatted rescue clauses" do
rescuer = [42]
- -> {
+ lambda {
begin
raise "error"
rescue *rescuer
@@ -384,23 +355,11 @@ describe "The rescue keyword" do
end
it "evaluates rescue expressions only when needed" do
+ invalid_rescuer = Object.new
begin
- ScratchPad << :foo
- rescue -> { ScratchPad << :bar; StandardError }.call
- end
-
- ScratchPad.recorded.should == [:foo]
- end
-
- it "suppresses exception from block when raises one from rescue expression" do
- -> {
- begin
- raise "from block"
- rescue (raise "from rescue expression")
- end
- }.should raise_error(RuntimeError, "from rescue expression") do |e|
- e.cause.message.should == "from block"
- end
+ :foo
+ rescue invalid_rescuer
+ end.should == :foo
end
it "should splat the handling Error classes" do
@@ -424,7 +383,7 @@ describe "The rescue keyword" do
end
it "does not allow rescue in {} block" do
- -> {
+ lambda {
eval <<-ruby
lambda {
raise SpecificExampleException
@@ -449,14 +408,22 @@ describe "The rescue keyword" do
end
end
- it "allows 'rescue' in method arguments" do
- two = eval '1.+ (raise("Error") rescue 1)'
- two.should == 2
+ ruby_version_is ""..."2.4" do
+ it "fails when using 'rescue' in method arguments" do
+ lambda { eval '1.+ (1 rescue 1)' }.should raise_error(SyntaxError)
+ end
end
- it "requires the 'rescue' in method arguments to be wrapped in parens" do
- -> { eval '1.+(1 rescue 1)' }.should raise_error(SyntaxError)
- eval('1.+((1 rescue 1))').should == 2
+ ruby_version_is "2.4" do
+ it "allows 'rescue' in method arguments" do
+ two = eval '1.+ (raise("Error") rescue 1)'
+ two.should == 2
+ end
+
+ it "requires the 'rescue' in method arguments to be wrapped in parens" do
+ lambda { eval '1.+(1 rescue 1)' }.should raise_error(SyntaxError)
+ eval('1.+((1 rescue 1))').should == 2
+ end
end
describe "inline form" do
@@ -466,7 +433,7 @@ describe "The rescue keyword" do
end
it "doesn't except rescue expression" do
- -> {
+ lambda {
eval <<-ruby
a = 1 rescue RuntimeError 2
ruby
@@ -477,7 +444,7 @@ describe "The rescue keyword" do
a = raise(StandardError) rescue 1
a.should == 1
- -> {
+ lambda {
a = raise(Exception) rescue 1
}.should raise_error(Exception)
end
diff --git a/spec/ruby/language/retry_spec.rb b/spec/ruby/language/retry_spec.rb
index ee5377946f..96e69b763a 100644
--- a/spec/ruby/language/retry_spec.rb
+++ b/spec/ruby/language/retry_spec.rb
@@ -1,4 +1,4 @@
-require_relative '../spec_helper'
+require File.expand_path('../../spec_helper', __FILE__)
describe "The retry statement" do
it "re-executes the closest block" do
@@ -32,7 +32,7 @@ describe "The retry statement" do
end
it "raises a SyntaxError when used outside of a begin statement" do
- -> { eval 'retry' }.should raise_error(SyntaxError)
+ lambda { eval 'retry' }.should raise_error(SyntaxError)
end
end
diff --git a/spec/ruby/language/return_spec.rb b/spec/ruby/language/return_spec.rb
index 7eef6d06ca..ba4bbfb5f3 100644
--- a/spec/ruby/language/return_spec.rb
+++ b/spec/ruby/language/return_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../spec_helper'
-require_relative 'fixtures/return'
+require File.expand_path('../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/return', __FILE__)
describe "The return keyword" do
it "returns any object directly" do
@@ -159,7 +159,7 @@ describe "The return keyword" do
end
it "executes the ensure clause when begin/ensure are inside a lambda" do
- -> do
+ lambda do
begin
return
ensure
@@ -176,15 +176,15 @@ describe "The return keyword" do
end
it "causes lambda to return nil if invoked without any arguments" do
- -> { return; 456 }.call.should be_nil
+ lambda { return; 456 }.call.should be_nil
end
it "causes lambda to return nil if invoked with an empty expression" do
- -> { return (); 456 }.call.should be_nil
+ lambda { return (); 456 }.call.should be_nil
end
it "causes lambda to return the value passed to return" do
- -> { return 123; 456 }.call.should == 123
+ lambda { return 123; 456 }.call.should == 123
end
it "causes the method that lexically encloses the block to return" do
@@ -362,7 +362,7 @@ describe "The return keyword" do
END_OF_CODE
end
- ruby_bug "#14061", "2.4"..."2.5" do
+ ruby_bug "#14061", "2.4"..."2.6" do
it "fires ensure block before returning while loads file" do
File.write(@filename, <<-END_OF_CODE)
ScratchPad << "before begin"
@@ -413,7 +413,7 @@ describe "The return keyword" do
ruby_version_is ""..."2.5" do
it "is allowed" do
File.write(@filename, <<-END_OF_CODE)
- class ReturnSpecs::A
+ class A
ScratchPad << "before return"
return
@@ -429,7 +429,7 @@ describe "The return keyword" do
ruby_version_is "2.5" do
it "raises a SyntaxError" do
File.write(@filename, <<-END_OF_CODE)
- class ReturnSpecs::A
+ class A
ScratchPad << "before return"
return
@@ -442,22 +442,6 @@ describe "The return keyword" do
end
end
- describe "within a block within a class" do
- ruby_version_is "2.7" do
- it "is not allowed" do
- File.write(@filename, <<-END_OF_CODE)
- class ReturnSpecs::A
- ScratchPad << "before return"
- 1.times { return }
- ScratchPad << "after return"
- end
- END_OF_CODE
-
- -> { load @filename }.should raise_error(LocalJumpError)
- end
- end
- end
-
describe "file loading" do
it "stops file loading and execution" do
File.write(@filename, <<-END_OF_CODE)
@@ -485,25 +469,13 @@ describe "The return keyword" do
end
describe "return with argument" do
- ruby_version_is ""..."2.7" do
- it "does not affect exit status" do
- ruby_exe(<<-END_OF_CODE).should == ""
- return 10
- END_OF_CODE
-
- $?.exitstatus.should == 0
- end
- end
-
- ruby_version_is "2.7" do
- it "warns but does not affect exit status" do
- err = ruby_exe(<<-END_OF_CODE, args: "2>&1")
- return 10
- END_OF_CODE
- $?.exitstatus.should == 0
+ # https://bugs.ruby-lang.org/issues/14062
+ it "does not affect exit status" do
+ ruby_exe(<<-END_OF_CODE).should == ""
+ return 10
+ END_OF_CODE
- err.should =~ /warning: argument of top-level return is ignored/
- end
+ $?.exitstatus.should == 0
end
end
end
diff --git a/spec/ruby/language/safe_navigator_spec.rb b/spec/ruby/language/safe_navigator_spec.rb
index c3aecff2dd..a8b29dc5a3 100644
--- a/spec/ruby/language/safe_navigator_spec.rb
+++ b/spec/ruby/language/safe_navigator_spec.rb
@@ -1,99 +1,101 @@
-require_relative '../spec_helper'
+require File.expand_path("../../spec_helper", __FILE__)
-describe "Safe navigator" do
- it "requires a method name to be provided" do
- -> { eval("obj&. {}") }.should raise_error(SyntaxError)
- end
-
- context "when context is nil" do
- it "always returns nil" do
- eval("nil&.unknown").should == nil
- eval("[][10]&.unknown").should == nil
+ruby_version_is "2.3" do
+ describe "Safe navigator" do
+ it "requires a method name to be provided" do
+ lambda { eval("obj&. {}") }.should raise_error(SyntaxError)
end
- it "can be chained" do
- eval("nil&.one&.two&.three").should == nil
- end
+ context "when context is nil" do
+ it "always returns nil" do
+ eval("nil&.unknown").should == nil
+ eval("[][10]&.unknown").should == nil
+ end
+
+ it "can be chained" do
+ eval("nil&.one&.two&.three").should == nil
+ end
- it "doesn't evaluate arguments" do
- obj = Object.new
- obj.should_not_receive(:m)
- eval("nil&.unknown(obj.m) { obj.m }")
+ it "doesn't evaluate arguments" do
+ obj = Object.new
+ obj.should_not_receive(:m)
+ eval("nil&.unknown(obj.m) { obj.m }")
+ end
end
- end
- context "when context is false" do
- it "calls the method" do
- eval("false&.to_s").should == "false"
+ context "when context is false" do
+ it "calls the method" do
+ eval("false&.to_s").should == "false"
- -> { eval("false&.unknown") }.should raise_error(NoMethodError)
+ lambda { eval("false&.unknown") }.should raise_error(NoMethodError)
+ end
end
- end
- context "when context is truthy" do
- it "calls the method" do
- eval("1&.to_s").should == "1"
+ context "when context is truthy" do
+ it "calls the method" do
+ eval("1&.to_s").should == "1"
- -> { eval("1&.unknown") }.should raise_error(NoMethodError)
+ lambda { eval("1&.unknown") }.should raise_error(NoMethodError)
+ end
end
- end
- it "takes a list of arguments" do
- eval("[1,2,3]&.first(2)").should == [1,2]
- end
+ it "takes a list of arguments" do
+ eval("[1,2,3]&.first(2)").should == [1,2]
+ end
- it "takes a block" do
- eval("[1,2]&.map { |i| i * 2 }").should == [2, 4]
- end
+ it "takes a block" do
+ eval("[1,2]&.map { |i| i * 2 }").should == [2, 4]
+ end
- it "allows assignment methods" do
- klass = Class.new do
- attr_reader :foo
- def foo=(val)
- @foo = val
- 42
+ it "allows assignment methods" do
+ klass = Class.new do
+ attr_reader :foo
+ def foo=(val)
+ @foo = val
+ 42
+ end
end
- end
- obj = klass.new
+ obj = klass.new
- eval("obj&.foo = 3").should == 3
- obj.foo.should == 3
+ eval("obj&.foo = 3").should == 3
+ obj.foo.should == 3
- obj = nil
- eval("obj&.foo = 3").should == nil
- end
+ obj = nil
+ eval("obj&.foo = 3").should == nil
+ end
- it "allows assignment operators" do
- klass = Class.new do
- attr_accessor :m
+ it "allows assignment operators" do
+ klass = Class.new do
+ attr_accessor :m
- def initialize
- @m = 0
+ def initialize
+ @m = 0
+ end
end
- end
- obj = klass.new
+ obj = klass.new
- eval("obj&.m += 3")
- obj.m.should == 3
+ eval("obj&.m += 3")
+ obj.m.should == 3
- obj = nil
- eval("obj&.m += 3").should == nil
- end
+ obj = nil
+ eval("obj&.m += 3").should == nil
+ end
- it "does not call the operator method lazily with an assignment operator" do
- klass = Class.new do
- attr_writer :foo
- def foo
- nil
+ it "does not call the operator method lazily with an assignment operator" do
+ klass = Class.new do
+ attr_writer :foo
+ def foo
+ nil
+ end
end
- end
- obj = klass.new
+ obj = klass.new
- -> {
- eval("obj&.foo += 3")
- }.should raise_error(NoMethodError) { |e|
- e.name.should == :+
- }
+ lambda {
+ eval("obj&.foo += 3")
+ }.should raise_error(NoMethodError) { |e|
+ e.name.should == :+
+ }
+ end
end
end
diff --git a/spec/ruby/language/safe_spec.rb b/spec/ruby/language/safe_spec.rb
deleted file mode 100644
index 53ab4f9561..0000000000
--- a/spec/ruby/language/safe_spec.rb
+++ /dev/null
@@ -1,138 +0,0 @@
-require_relative '../spec_helper'
-
-describe "The $SAFE variable" do
- ruby_version_is ""..."2.7" do
- ruby_version_is "2.6" do
- after :each do
- $SAFE = 0
- end
- end
-
- it "is 0 by default" do
- $SAFE.should == 0
- proc {
- $SAFE.should == 0
- }.call
- end
-
- it "can be set to 0" do
- proc {
- $SAFE = 0
- $SAFE.should == 0
- }.call
- end
-
- it "can be set to 1" do
- proc {
- $SAFE = 1
- $SAFE.should == 1
- }.call
- end
-
- [2, 3, 4].each do |n|
- it "cannot be set to #{n}" do
- -> {
- proc {
- $SAFE = n
- }.call
- }.should raise_error(ArgumentError, /\$SAFE=2 to 4 are obsolete/)
- end
- end
-
- ruby_version_is ""..."2.6" do
- it "cannot be set to values below 0" do
- -> {
- proc {
- $SAFE = -100
- }.call
- }.should raise_error(SecurityError, /tried to downgrade safe level from 0 to -100/)
- end
- end
-
- ruby_version_is "2.6" do
- it "raises ArgumentError when set to values below 0" do
- -> {
- proc {
- $SAFE = -100
- }.call
- }.should raise_error(ArgumentError, "$SAFE should be >= 0")
- end
- end
-
- it "cannot be set to values above 4" do
- -> {
- proc {
- $SAFE = 100
- }.call
- }.should raise_error(ArgumentError, /\$SAFE=2 to 4 are obsolete/)
- end
-
- ruby_version_is ""..."2.6" do
- it "cannot be manually lowered" do
- proc {
- $SAFE = 1
- -> {
- $SAFE = 0
- }.should raise_error(SecurityError, /tried to downgrade safe level from 1 to 0/)
- }.call
- end
-
- it "is automatically lowered when leaving a proc" do
- $SAFE.should == 0
- proc {
- $SAFE = 1
- }.call
- $SAFE.should == 0
- end
-
- it "is automatically lowered when leaving a lambda" do
- $SAFE.should == 0
- -> {
- $SAFE = 1
- }.call
- $SAFE.should == 0
- end
- end
-
- ruby_version_is "2.6" do
- it "can be manually lowered" do
- $SAFE = 1
- $SAFE = 0
- $SAFE.should == 0
- end
-
- it "is not Proc local" do
- $SAFE.should == 0
- proc {
- $SAFE = 1
- }.call
- $SAFE.should == 1
- end
-
- it "is not lambda local" do
- $SAFE.should == 0
- -> {
- $SAFE = 1
- }.call
- $SAFE.should == 1
- end
-
- it "is global like regular global variables" do
- Thread.new { $SAFE }.value.should == 0
- $SAFE = 1
- Thread.new { $SAFE }.value.should == 1
- end
- end
-
- it "can be read when default from Thread#safe_level" do
- Thread.current.safe_level.should == 0
- end
-
- it "can be read when modified from Thread#safe_level" do
- proc {
- $SAFE = 1
- Thread.current.safe_level.should == 1
- }.call
- end
- end
-end
diff --git a/spec/ruby/language/send_spec.rb b/spec/ruby/language/send_spec.rb
index c56d5e8c26..646a700785 100644
--- a/spec/ruby/language/send_spec.rb
+++ b/spec/ruby/language/send_spec.rb
@@ -1,15 +1,15 @@
-require_relative '../spec_helper'
-require_relative 'fixtures/send'
+require File.expand_path('../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/send', __FILE__)
# Why so many fixed arg tests? JRuby and I assume other Ruby impls have
# separate call paths for simple fixed arity methods. Testing up to five
# will verify special and generic arity code paths for all impls.
#
# Method naming conventions:
-# M - Mandatory Args
+# M - Manditory Args
# O - Optional Arg
# R - Rest Arg
-# Q - Post Mandatory Args
+# Q - Post Manditory Args
specs = LangSendSpecs
@@ -20,7 +20,7 @@ describe "Invoking a method" do
end
it "raises ArgumentError if the method has a positive arity" do
- -> {
+ lambda {
specs.fooM1
}.should raise_error(ArgumentError)
end
@@ -36,7 +36,7 @@ describe "Invoking a method" do
end
it "raises ArgumentError if the methods arity doesn't match" do
- -> {
+ lambda {
specs.fooM1(1,2)
}.should raise_error(ArgumentError)
end
@@ -52,7 +52,7 @@ describe "Invoking a method" do
end
it "raises ArgumentError if extra arguments are passed" do
- -> {
+ lambda {
specs.fooM0O1(2,3)
}.should raise_error(ArgumentError)
end
@@ -64,13 +64,13 @@ describe "Invoking a method" do
end
it "raises an ArgumentError if there are no values for the mandatory args" do
- -> {
+ lambda {
specs.fooM1O1
}.should raise_error(ArgumentError)
end
it "raises an ArgumentError if too many values are passed" do
- -> {
+ lambda {
specs.fooM1O1(1,2,3)
}.should raise_error(ArgumentError)
end
@@ -107,7 +107,7 @@ describe "Invoking a method" do
end
it "raises a SyntaxError with both a literal block and an object as block" do
- -> {
+ lambda {
eval "specs.oneb(10, &l){ 42 }"
}.should raise_error(SyntaxError)
end
@@ -195,20 +195,12 @@ describe "Invoking a method" do
end
it "raises NameError if invoked as a vcall" do
- -> { no_such_method }.should raise_error NameError
- end
-
- it "should omit the method_missing call from the backtrace for NameError" do
- -> { no_such_method }.should raise_error { |e| e.backtrace.first.should_not include("method_missing") }
+ lambda { no_such_method }.should raise_error NameError
end
it "raises NoMethodError if invoked as an unambiguous method call" do
- -> { no_such_method() }.should raise_error NoMethodError
- -> { no_such_method(1,2,3) }.should raise_error NoMethodError
- end
-
- it "should omit the method_missing call from the backtrace for NoMethodError" do
- -> { no_such_method() }.should raise_error { |e| e.backtrace.first.should_not include("method_missing") }
+ lambda { no_such_method() }.should raise_error NoMethodError
+ lambda { no_such_method(1,2,3) }.should raise_error NoMethodError
end
end
@@ -258,20 +250,10 @@ describe "Invoking a private setter method" do
end
describe "Invoking a private getter method" do
- ruby_version_is ""..."2.7" do
- it "does not permit self as a receiver" do
- receiver = LangSendSpecs::PrivateGetter.new
- -> { receiver.call_self_foo }.should raise_error(NoMethodError)
- -> { receiver.call_self_foo_or_equals(6) }.should raise_error(NoMethodError)
- end
- end
-
- ruby_version_is "2.7" do
- it "permits self as a receiver" do
- receiver = LangSendSpecs::PrivateGetter.new
- receiver.call_self_foo_or_equals(6)
- receiver.call_self_foo.should == 6
- end
+ it "does not permit self as a receiver" do
+ receiver = LangSendSpecs::PrivateGetter.new
+ lambda { receiver.call_self_foo }.should raise_error(NoMethodError)
+ lambda { receiver.call_self_foo_or_equals(6) }.should raise_error(NoMethodError)
end
end
@@ -421,29 +403,6 @@ describe "Invoking a method" do
specs.rest_len(0,*a,4,*5,6,7,*c,-1).should == 11
end
- it "expands the Array elements from the splat after executing the arguments and block if no other arguments follow the splat" do
- def self.m(*args, &block)
- [args, block]
- end
-
- args = [1, nil]
- m(*args, &args.pop).should == [[1], nil]
-
- args = [1, nil]
- order = []
- m(*(order << :args; args), &(order << :block; args.pop)).should == [[1], nil]
- order.should == [:args, :block]
- end
-
- it "evaluates the splatted arguments before the block if there are other arguments after the splat" do
- def self.m(*args, &block)
- [args, block]
- end
-
- args = [1, nil]
- m(*args, 2, &args.pop).should == [[1, nil, 2], nil]
- end
-
it "expands an array to arguments grouped in parentheses" do
specs.destructure2([40,2]).should == 42
end
diff --git a/spec/ruby/language/singleton_class_spec.rb b/spec/ruby/language/singleton_class_spec.rb
index df735018af..837f479440 100644
--- a/spec/ruby/language/singleton_class_spec.rb
+++ b/spec/ruby/language/singleton_class_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/class'
+require File.expand_path('../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/class', __FILE__)
describe "A singleton class" do
it "is TrueClass for true" do
@@ -15,11 +15,11 @@ describe "A singleton class" do
end
it "raises a TypeError for Fixnum's" do
- -> { 1.singleton_class }.should raise_error(TypeError)
+ lambda { 1.singleton_class }.should raise_error(TypeError)
end
it "raises a TypeError for symbols" do
- -> { :symbol.singleton_class }.should raise_error(TypeError)
+ lambda { :symbol.singleton_class }.should raise_error(TypeError)
end
it "is a singleton Class instance" do
@@ -74,7 +74,7 @@ describe "A singleton class" do
end
it "doesn't have singleton class" do
- -> { bignum_value.singleton_class.superclass.should == Bignum }.should raise_error(TypeError)
+ lambda { bignum_value.singleton_class.superclass.should == Bignum }.should raise_error(TypeError)
end
end
@@ -112,11 +112,11 @@ describe "A constant on a singleton class" do
class << @object
CONST
end
- -> { CONST }.should raise_error(NameError)
+ lambda { CONST }.should raise_error(NameError)
end
it "cannot be accessed via object::CONST" do
- -> do
+ lambda do
@object::CONST
end.should raise_error(TypeError)
end
@@ -127,7 +127,7 @@ describe "A constant on a singleton class" do
CONST = 100
end
- -> do
+ lambda do
@object::CONST
end.should raise_error(NameError)
end
@@ -143,7 +143,7 @@ describe "A constant on a singleton class" do
it "is not preserved when the object is duped" do
@object = @object.dup
- -> do
+ lambda do
class << @object; CONST; end
end.should raise_error(NameError)
end
@@ -280,13 +280,13 @@ end
describe "Instantiating a singleton class" do
it "raises a TypeError when new is called" do
- -> {
+ lambda {
Object.new.singleton_class.new
}.should raise_error(TypeError)
end
it "raises a TypeError when allocate is called" do
- -> {
+ lambda {
Object.new.singleton_class.allocate
}.should raise_error(TypeError)
end
diff --git a/spec/ruby/language/source_encoding_spec.rb b/spec/ruby/language/source_encoding_spec.rb
deleted file mode 100644
index a0a29f63de..0000000000
--- a/spec/ruby/language/source_encoding_spec.rb
+++ /dev/null
@@ -1,61 +0,0 @@
-require_relative '../spec_helper'
-
-describe "Source files" do
-
- describe "encoded in UTF-8 without a BOM" do
- it "can be parsed" do
- ruby_exe(fixture(__FILE__, "utf8-nobom.rb"), args: "2>&1").should == "hello\n"
- end
- end
-
- describe "encoded in UTF-8 with a BOM" do
- it "can be parsed" do
- ruby_exe(fixture(__FILE__, "utf8-bom.rb"), args: "2>&1").should == "hello\n"
- end
- end
-
- describe "encoded in UTF-16 LE without a BOM" do
- it "are parsed because empty as they contain a NUL byte before the encoding comment" do
- ruby_exe(fixture(__FILE__, "utf16-le-nobom.rb"), args: "2>&1").should == ""
- end
- end
-
- describe "encoded in UTF-16 LE with a BOM" do
- it "are invalid because they contain an invalid UTF-8 sequence before the encoding comment" do
- bom = "\xFF\xFE".b
- source = "# encoding: utf-16le\nputs 'hello'\n"
- source = bom + source.bytes.zip([0]*source.bytesize).flatten.pack('C*')
- path = tmp("utf16-le-bom.rb")
-
- touch(path, "wb") { |f| f.write source }
- begin
- ruby_exe(path, args: "2>&1").should =~ /invalid multibyte char/
- ensure
- rm_r path
- end
- end
- end
-
- describe "encoded in UTF-16 BE without a BOM" do
- it "are parsed as empty because they contain a NUL byte before the encoding comment" do
- ruby_exe(fixture(__FILE__, "utf16-be-nobom.rb"), args: "2>&1").should == ""
- end
- end
-
- describe "encoded in UTF-16 BE with a BOM" do
- it "are invalid because they contain an invalid UTF-8 sequence before the encoding comment" do
- bom = "\xFE\xFF".b
- source = "# encoding: utf-16be\nputs 'hello'\n"
- source = bom + ([0]*source.bytesize).zip(source.bytes).flatten.pack('C*')
- path = tmp("utf16-be-bom.rb")
-
- touch(path, "wb") { |f| f.write source }
- begin
- ruby_exe(path, args: "2>&1").should =~ /invalid multibyte char/
- ensure
- rm_r path
- end
- end
- end
-
-end
diff --git a/spec/ruby/language/string_spec.rb b/spec/ruby/language/string_spec.rb
index d0f62ff3c9..dbec2652ed 100644
--- a/spec/ruby/language/string_spec.rb
+++ b/spec/ruby/language/string_spec.rb
@@ -1,6 +1,6 @@
# -*- encoding: binary -*-
-require_relative '../spec_helper'
+require File.expand_path('../../spec_helper', __FILE__)
# TODO: rewrite these horrid specs. it "are..." seriously?!
@@ -42,35 +42,24 @@ describe "Ruby character strings" do
"#@ip#@ip".should == 'xxxxxx'
end
- it "don't get confused by partial interpolation character sequences" do
- "#@".should == '#@'
- "#@ ".should == '#@ '
- "#@@".should == '#@@'
- "#@@ ".should == '#@@ '
- "#$ ".should == '#$ '
- "#\$".should == '#$'
- end
-
- ruby_version_is ''...'2.7' do
- it "taints the result of interpolation when an interpolated value is tainted" do
- "#{"".taint}".tainted?.should be_true
+ it "taints the result of interpolation when an interpolated value is tainted" do
+ "#{"".taint}".tainted?.should be_true
- @ip.taint
- "#@ip".tainted?.should be_true
+ @ip.taint
+ "#@ip".tainted?.should be_true
- $ip.taint
- "#$ip".tainted?.should be_true
- end
+ $ip.taint
+ "#$ip".tainted?.should be_true
+ end
- it "untrusts the result of interpolation when an interpolated value is untrusted" do
- "#{"".untrust}".untrusted?.should be_true
+ it "untrusts the result of interpolation when an interpolated value is untrusted" do
+ "#{"".untrust}".untrusted?.should be_true
- @ip.untrust
- "#@ip".untrusted?.should be_true
+ @ip.untrust
+ "#@ip".untrusted?.should be_true
- $ip.untrust
- "#$ip".untrusted?.should be_true
- end
+ $ip.untrust
+ "#$ip".untrusted?.should be_true
end
it "allows using non-alnum characters as string delimiters" do
@@ -197,11 +186,11 @@ describe "Ruby character strings" do
# TODO: spec other source encodings
describe "with ASCII_8BIT source encoding" do
it "produces an ASCII string when escaping ASCII characters via \\u" do
- "\u0000".encoding.should == Encoding::BINARY
+ "\u0000".encoding.should == Encoding::ASCII_8BIT
end
it "produces an ASCII string when escaping ASCII characters via \\u{}" do
- "\u{0000}".encoding.should == Encoding::BINARY
+ "\u{0000}".encoding.should == Encoding::ASCII_8BIT
end
it "produces a UTF-8-encoded string when escaping non-ASCII characters via \\u" do
@@ -235,55 +224,59 @@ describe "Ruby String literals" do
long_string_literals.should == "Beautiful is better than ugly.Explicit is better than implicit."
end
- describe "with a magic frozen comment" do
- it "produce the same object each time" do
- ruby_exe(fixture(__FILE__, "freeze_magic_comment_one_literal.rb")).chomp.should == "true"
- end
+ ruby_version_is "2.3" do
+ describe "with a magic frozen comment" do
+ it "produce the same object each time" do
+ ruby_exe(fixture(__FILE__, "freeze_magic_comment_one_literal.rb")).chomp.should == "true"
+ end
- it "produce the same object for literals with the same content" do
- ruby_exe(fixture(__FILE__, "freeze_magic_comment_two_literals.rb")).chomp.should == "true"
- end
+ it "produce the same object for literals with the same content" do
+ ruby_exe(fixture(__FILE__, "freeze_magic_comment_two_literals.rb")).chomp.should == "true"
+ end
- it "produce the same object for literals with the same content in different files" do
- ruby_exe(fixture(__FILE__, "freeze_magic_comment_across_files.rb")).chomp.should == "true"
- end
+ it "produce the same object for literals with the same content in different files" do
+ ruby_exe(fixture(__FILE__, "freeze_magic_comment_across_files.rb")).chomp.should == "true"
+ end
- it "produce different objects for literals with the same content in different files if the other file doesn't have the comment" do
- ruby_exe(fixture(__FILE__, "freeze_magic_comment_across_files_no_comment.rb")).chomp.should == "true"
- end
+ it "produce different objects for literals with the same content in different files if the other file doesn't have the comment" do
+ ruby_exe(fixture(__FILE__, "freeze_magic_comment_across_files_no_comment.rb")).chomp.should == "true"
+ end
- it "produce different objects for literals with the same content in different files if they have different encodings" do
- ruby_exe(fixture(__FILE__, "freeze_magic_comment_across_files_diff_enc.rb")).chomp.should == "true"
+ it "produce different objects for literals with the same content in different files if they have different encodings" do
+ ruby_exe(fixture(__FILE__, "freeze_magic_comment_across_files_diff_enc.rb")).chomp.should == "true"
+ end
end
end
end
-describe "Ruby String interpolation" do
- it "creates a String having an Encoding compatible with all components" do
- a = "\u3042"
- b = "abc".encode("binary")
+with_feature :encoding do
+ describe "Ruby String interpolation" do
+ it "creates a String having an Encoding compatible with all components" do
+ a = "\u3042"
+ b = "abc".encode("ascii-8bit")
- str = "#{a} x #{b}"
+ str = "#{a} x #{b}"
- str.should == "\xe3\x81\x82\x20\x78\x20\x61\x62\x63".force_encoding("utf-8")
- str.encoding.should == Encoding::UTF_8
- end
+ str.should == "\xe3\x81\x82\x20\x78\x20\x61\x62\x63".force_encoding("utf-8")
+ str.encoding.should == Encoding::UTF_8
+ end
- it "creates a String having the Encoding of the components when all are the same Encoding" do
- a = "abc".force_encoding("euc-jp")
- b = "def".force_encoding("euc-jp")
- str = '"#{a} x #{b}"'.force_encoding("euc-jp")
+ it "creates a String having the Encoding of the components when all are the same Encoding" do
+ a = "abc".force_encoding("euc-jp")
+ b = "def".force_encoding("euc-jp")
+ str = '"#{a} x #{b}"'.force_encoding("euc-jp")
- result = eval(str)
- result.should == "\x61\x62\x63\x20\x78\x20\x64\x65\x66".force_encoding("euc-jp")
- result.encoding.should == Encoding::EUC_JP
- end
+ result = eval(str)
+ result.should == "\x61\x62\x63\x20\x78\x20\x64\x65\x66".force_encoding("euc-jp")
+ result.encoding.should == Encoding::EUC_JP
+ end
- it "raises an Encoding::CompatibilityError if the Encodings are not compatible" do
- a = "\u3042"
- b = "\xff".force_encoding "binary"
+ it "raises an Encoding::CompatibilityError if the Encodings are not compatible" do
+ a = "\u3042"
+ b = "\xff".force_encoding "ascii-8bit"
- -> { "#{a} #{b}" }.should raise_error(Encoding::CompatibilityError)
+ lambda { "#{a} #{b}" }.should raise_error(Encoding::CompatibilityError)
+ end
end
end
diff --git a/spec/ruby/language/super_spec.rb b/spec/ruby/language/super_spec.rb
index 66a1ec7592..3d3f5d6f74 100644
--- a/spec/ruby/language/super_spec.rb
+++ b/spec/ruby/language/super_spec.rb
@@ -1,73 +1,73 @@
-require_relative '../spec_helper'
-require_relative 'fixtures/super'
+require File.expand_path('../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/super', __FILE__)
describe "The super keyword" do
it "calls the method on the calling class" do
- SuperSpecs::S1::A.new.foo([]).should == ["A#foo","A#bar"]
- SuperSpecs::S1::A.new.bar([]).should == ["A#bar"]
- SuperSpecs::S1::B.new.foo([]).should == ["B#foo","A#foo","B#bar","A#bar"]
- SuperSpecs::S1::B.new.bar([]).should == ["B#bar","A#bar"]
+ Super::S1::A.new.foo([]).should == ["A#foo","A#bar"]
+ Super::S1::A.new.bar([]).should == ["A#bar"]
+ Super::S1::B.new.foo([]).should == ["B#foo","A#foo","B#bar","A#bar"]
+ Super::S1::B.new.bar([]).should == ["B#bar","A#bar"]
end
it "searches the full inheritance chain" do
- SuperSpecs::S2::B.new.foo([]).should == ["B#foo","A#baz"]
- SuperSpecs::S2::B.new.baz([]).should == ["A#baz"]
- SuperSpecs::S2::C.new.foo([]).should == ["B#foo","C#baz","A#baz"]
- SuperSpecs::S2::C.new.baz([]).should == ["C#baz","A#baz"]
+ Super::S2::B.new.foo([]).should == ["B#foo","A#baz"]
+ Super::S2::B.new.baz([]).should == ["A#baz"]
+ Super::S2::C.new.foo([]).should == ["B#foo","C#baz","A#baz"]
+ Super::S2::C.new.baz([]).should == ["C#baz","A#baz"]
end
it "searches class methods" do
- SuperSpecs::S3::A.new.foo([]).should == ["A#foo"]
- SuperSpecs::S3::A.foo([]).should == ["A.foo"]
- SuperSpecs::S3::A.bar([]).should == ["A.bar","A.foo"]
- SuperSpecs::S3::B.new.foo([]).should == ["A#foo"]
- SuperSpecs::S3::B.foo([]).should == ["B.foo","A.foo"]
- SuperSpecs::S3::B.bar([]).should == ["B.bar","A.bar","B.foo","A.foo"]
+ Super::S3::A.new.foo([]).should == ["A#foo"]
+ Super::S3::A.foo([]).should == ["A.foo"]
+ Super::S3::A.bar([]).should == ["A.bar","A.foo"]
+ Super::S3::B.new.foo([]).should == ["A#foo"]
+ Super::S3::B.foo([]).should == ["B.foo","A.foo"]
+ Super::S3::B.bar([]).should == ["B.bar","A.bar","B.foo","A.foo"]
end
it "calls the method on the calling class including modules" do
- SuperSpecs::MS1::A.new.foo([]).should == ["ModA#foo","ModA#bar"]
- SuperSpecs::MS1::A.new.bar([]).should == ["ModA#bar"]
- SuperSpecs::MS1::B.new.foo([]).should == ["B#foo","ModA#foo","ModB#bar","ModA#bar"]
- SuperSpecs::MS1::B.new.bar([]).should == ["ModB#bar","ModA#bar"]
+ Super::MS1::A.new.foo([]).should == ["ModA#foo","ModA#bar"]
+ Super::MS1::A.new.bar([]).should == ["ModA#bar"]
+ Super::MS1::B.new.foo([]).should == ["B#foo","ModA#foo","ModB#bar","ModA#bar"]
+ Super::MS1::B.new.bar([]).should == ["ModB#bar","ModA#bar"]
end
it "searches the full inheritance chain including modules" do
- SuperSpecs::MS2::B.new.foo([]).should == ["ModB#foo","A#baz"]
- SuperSpecs::MS2::B.new.baz([]).should == ["A#baz"]
- SuperSpecs::MS2::C.new.baz([]).should == ["C#baz","A#baz"]
- SuperSpecs::MS2::C.new.foo([]).should == ["ModB#foo","C#baz","A#baz"]
+ Super::MS2::B.new.foo([]).should == ["ModB#foo","A#baz"]
+ Super::MS2::B.new.baz([]).should == ["A#baz"]
+ Super::MS2::C.new.baz([]).should == ["C#baz","A#baz"]
+ Super::MS2::C.new.foo([]).should == ["ModB#foo","C#baz","A#baz"]
end
it "can resolve to different methods in an included module method" do
- SuperSpecs::MultiSuperTargets::A.new.foo.should == :BaseA
- SuperSpecs::MultiSuperTargets::B.new.foo.should == :BaseB
+ Super::MultiSuperTargets::A.new.foo.should == :BaseA
+ Super::MultiSuperTargets::B.new.foo.should == :BaseB
end
it "searches class methods including modules" do
- SuperSpecs::MS3::A.new.foo([]).should == ["A#foo"]
- SuperSpecs::MS3::A.foo([]).should == ["ModA#foo"]
- SuperSpecs::MS3::A.bar([]).should == ["ModA#bar","ModA#foo"]
- SuperSpecs::MS3::B.new.foo([]).should == ["A#foo"]
- SuperSpecs::MS3::B.foo([]).should == ["B.foo","ModA#foo"]
- SuperSpecs::MS3::B.bar([]).should == ["B.bar","ModA#bar","B.foo","ModA#foo"]
+ Super::MS3::A.new.foo([]).should == ["A#foo"]
+ Super::MS3::A.foo([]).should == ["ModA#foo"]
+ Super::MS3::A.bar([]).should == ["ModA#bar","ModA#foo"]
+ Super::MS3::B.new.foo([]).should == ["A#foo"]
+ Super::MS3::B.foo([]).should == ["B.foo","ModA#foo"]
+ Super::MS3::B.bar([]).should == ["B.bar","ModA#bar","B.foo","ModA#foo"]
end
it "searches BasicObject from a module for methods defined there" do
- SuperSpecs::IncludesFromBasic.new.__send__(:foobar).should == 43
+ Super::IncludesFromBasic.new.__send__(:foobar).should == 43
end
it "searches BasicObject through another module for methods defined there" do
- SuperSpecs::IncludesIntermediate.new.__send__(:foobar).should == 42
+ Super::IncludesIntermediate.new.__send__(:foobar).should == 42
end
it "calls the correct method when the method visibility is modified" do
- SuperSpecs::MS4::A.new.example.should == 5
+ Super::MS4::A.new.example.should == 5
end
it "calls the correct method when the superclass argument list is different from the subclass" do
- SuperSpecs::S4::A.new.foo([]).should == ["A#foo"]
- SuperSpecs::S4::B.new.foo([],"test").should == ["B#foo(a,test)", "A#foo"]
+ Super::S4::A.new.foo([]).should == ["A#foo"]
+ Super::S4::B.new.foo([],"test").should == ["B#foo(a,test)", "A#foo"]
end
it "raises an error error when super method does not exist" do
@@ -83,8 +83,8 @@ describe "The super keyword" do
end
end
- -> {sub_normal.new.foo}.should raise_error(NoMethodError, /super/)
- -> {sub_zsuper.new.foo}.should raise_error(NoMethodError, /super/)
+ lambda {sub_normal.new.foo}.should raise_error(NoMethodError, /super/)
+ lambda {sub_zsuper.new.foo}.should raise_error(NoMethodError, /super/)
end
it "uses given block even if arguments are passed explicitly" do
@@ -102,35 +102,16 @@ describe "The super keyword" do
c2.new.m(:dump) { :value }.should == :value
end
- it "uses block argument given to method when used in a block" do
- c1 = Class.new do
- def m
- yield
- end
- end
- c2 = Class.new(c1) do
- def m(v)
- ary = []
- 1.times do
- ary << super()
- end
- ary
- end
- end
-
- c2.new.m(:dump) { :value }.should == [ :value ]
- end
-
it "calls the superclass method when in a block" do
- SuperSpecs::S6.new.here.should == :good
+ Super::S6.new.here.should == :good
end
it "calls the superclass method when initial method is defined_method'd" do
- SuperSpecs::S7.new.here.should == :good
+ Super::S7.new.here.should == :good
end
it "can call through a define_method multiple times (caching check)" do
- obj = SuperSpecs::S7.new
+ obj = Super::S7.new
2.times do
obj.here.should == :good
@@ -169,25 +150,25 @@ describe "The super keyword" do
end
end
- -> { klass.new.a(:a_called) }.should raise_error(RuntimeError)
+ lambda { klass.new.a(:a_called) }.should raise_error(RuntimeError)
end
# Rubinius ticket github#157
it "calls method_missing when a superclass method is not found" do
- SuperSpecs::MM_B.new.is_a?(Hash).should == false
+ Super::MM_B.new.is_a?(Hash).should == false
end
# Rubinius ticket github#180
it "respects the original module a method is aliased from" do
- SuperSpecs::Alias3.new.name3.should == [:alias2, :alias1]
+ Super::Alias3.new.name3.should == [:alias2, :alias1]
end
it "sees the included version of a module a method is alias from" do
- SuperSpecs::AliasWithSuper::Trigger.foo.should == [:b, :a]
+ Super::AliasWithSuper::Trigger.foo.should == [:b, :a]
end
it "find super from a singleton class" do
- obj = SuperSpecs::SingletonCase::Foo.new
+ obj = Super::SingletonCase::Foo.new
def obj.foobar(array)
array << :singleton
super
@@ -196,97 +177,87 @@ describe "The super keyword" do
end
it "finds super on other objects if a singleton class aliased the method" do
- orig_obj = SuperSpecs::SingletonAliasCase::Foo.new
+ orig_obj = Super::SingletonAliasCase::Foo.new
orig_obj.alias_on_singleton
orig_obj.new_foobar([]).should == [:foo, :base]
- SuperSpecs::SingletonAliasCase::Foo.new.foobar([]).should == [:foo, :base]
+ Super::SingletonAliasCase::Foo.new.foobar([]).should == [:foo, :base]
end
it "passes along modified rest args when they weren't originally empty" do
- SuperSpecs::RestArgsWithSuper::B.new.a("bar").should == ["bar", "foo"]
+ Super::RestArgsWithSuper::B.new.a("bar").should == ["bar", "foo"]
end
it "passes along modified rest args when they were originally empty" do
- SuperSpecs::RestArgsWithSuper::B.new.a.should == ["foo"]
- end
-
- # https://bugs.ruby-lang.org/issues/14279
- it "passes along reassigned rest args" do
- SuperSpecs::ZSuperWithRestReassigned::B.new.a("bar").should == ["foo"]
- end
-
- # https://bugs.ruby-lang.org/issues/14279
- it "wraps into array and passes along reassigned rest args with non-array scalar value" do
- SuperSpecs::ZSuperWithRestReassignedWithScalar::B.new.a("bar").should == ["foo"]
+ Super::RestArgsWithSuper::B.new.a.should == ["foo"]
end
it "invokes methods from a chain of anonymous modules" do
- SuperSpecs::AnonymousModuleIncludedTwice.new.a([]).should == ["anon", "anon", "non-anon"]
+ Super::AnonymousModuleIncludedTwice.new.a([]).should == ["anon", "anon", "non-anon"]
end
it "without explicit arguments can accept a block but still pass the original arguments" do
- SuperSpecs::ZSuperWithBlock::B.new.a.should == 14
+ Super::ZSuperWithBlock::B.new.a.should == 14
end
it "passes along block via reference to method expecting a reference" do
- SuperSpecs::ZSuperWithBlock::B.new.b.should == [14, 15]
+ Super::ZSuperWithBlock::B.new.b.should == [14, 15]
end
it "passes along a block via reference to a method that yields" do
- SuperSpecs::ZSuperWithBlock::B.new.c.should == 16
+ Super::ZSuperWithBlock::B.new.c.should == 16
end
it "without explicit arguments passes optional arguments that have a default value" do
- SuperSpecs::ZSuperWithOptional::B.new.m(1, 2).should == 14
+ Super::ZSuperWithOptional::B.new.m(1, 2).should == 14
end
it "without explicit arguments passes optional arguments that have a non-default value" do
- SuperSpecs::ZSuperWithOptional::B.new.m(1, 2, 3).should == 3
+ Super::ZSuperWithOptional::B.new.m(1, 2, 3).should == 3
end
it "without explicit arguments passes optional arguments that have a default value but were modified" do
- SuperSpecs::ZSuperWithOptional::C.new.m(1, 2).should == 100
+ Super::ZSuperWithOptional::C.new.m(1, 2).should == 100
end
it "without explicit arguments passes optional arguments that have a non-default value but were modified" do
- SuperSpecs::ZSuperWithOptional::C.new.m(1, 2, 3).should == 100
+ Super::ZSuperWithOptional::C.new.m(1, 2, 3).should == 100
end
it "without explicit arguments passes rest arguments" do
- SuperSpecs::ZSuperWithRest::B.new.m(1, 2, 3).should == [1, 2, 3]
+ Super::ZSuperWithRest::B.new.m(1, 2, 3).should == [1, 2, 3]
end
it "without explicit arguments passes rest arguments including any modifications" do
- SuperSpecs::ZSuperWithRest::B.new.m_modified(1, 2, 3).should == [1, 14, 3]
+ Super::ZSuperWithRest::B.new.m_modified(1, 2, 3).should == [1, 14, 3]
end
it "without explicit arguments passes arguments and rest arguments" do
- SuperSpecs::ZSuperWithRestAndOthers::B.new.m(1, 2, 3, 4, 5).should == [3, 4, 5]
+ Super::ZSuperWithRestAndOthers::B.new.m(1, 2, 3, 4, 5).should == [3, 4, 5]
end
it "without explicit arguments passes arguments and rest arguments including any modifications" do
- SuperSpecs::ZSuperWithRestAndOthers::B.new.m_modified(1, 2, 3, 4, 5).should == [3, 14, 5]
+ Super::ZSuperWithRestAndOthers::B.new.m_modified(1, 2, 3, 4, 5).should == [3, 14, 5]
end
it "without explicit arguments that are '_'" do
- SuperSpecs::ZSuperWithUnderscores::B.new.m(1, 2).should == [1, 2]
+ Super::ZSuperWithUnderscores::B.new.m(1, 2).should == [1, 2]
end
it "without explicit arguments that are '_' including any modifications" do
- SuperSpecs::ZSuperWithUnderscores::B.new.m_modified(1, 2).should == [14, 2]
+ Super::ZSuperWithUnderscores::B.new.m_modified(1, 2).should == [14, 2]
end
describe 'when using keyword arguments' do
before :each do
- @req = SuperSpecs::Keywords::RequiredArguments.new
- @opts = SuperSpecs::Keywords::OptionalArguments.new
- @etc = SuperSpecs::Keywords::PlaceholderArguments.new
+ @req = Super::Keywords::RequiredArguments.new
+ @opts = Super::Keywords::OptionalArguments.new
+ @etc = Super::Keywords::PlaceholderArguments.new
- @req_and_opts = SuperSpecs::Keywords::RequiredAndOptionalArguments.new
- @req_and_etc = SuperSpecs::Keywords::RequiredAndPlaceholderArguments.new
- @opts_and_etc = SuperSpecs::Keywords::OptionalAndPlaceholderArguments.new
+ @req_and_opts = Super::Keywords::RequiredAndOptionalArguments.new
+ @req_and_etc = Super::Keywords::RequiredAndPlaceholderArguments.new
+ @opts_and_etc = Super::Keywords::OptionalAndPlaceholderArguments.new
- @req_and_opts_and_etc = SuperSpecs::Keywords::RequiredAndOptionalAndPlaceholderArguments.new
+ @req_and_opts_and_etc = Super::Keywords::RequiredAndOptionalAndPlaceholderArguments.new
end
it 'does not pass any arguments to the parent when none are given' do
@@ -322,15 +293,15 @@ describe "The super keyword" do
describe 'when using regular and keyword arguments' do
before :each do
- @req = SuperSpecs::RegularAndKeywords::RequiredArguments.new
- @opts = SuperSpecs::RegularAndKeywords::OptionalArguments.new
- @etc = SuperSpecs::RegularAndKeywords::PlaceholderArguments.new
+ @req = Super::RegularAndKeywords::RequiredArguments.new
+ @opts = Super::RegularAndKeywords::OptionalArguments.new
+ @etc = Super::RegularAndKeywords::PlaceholderArguments.new
- @req_and_opts = SuperSpecs::RegularAndKeywords::RequiredAndOptionalArguments.new
- @req_and_etc = SuperSpecs::RegularAndKeywords::RequiredAndPlaceholderArguments.new
- @opts_and_etc = SuperSpecs::RegularAndKeywords::OptionalAndPlaceholderArguments.new
+ @req_and_opts = Super::RegularAndKeywords::RequiredAndOptionalArguments.new
+ @req_and_etc = Super::RegularAndKeywords::RequiredAndPlaceholderArguments.new
+ @opts_and_etc = Super::RegularAndKeywords::OptionalAndPlaceholderArguments.new
- @req_and_opts_and_etc = SuperSpecs::RegularAndKeywords::RequiredAndOptionalAndPlaceholderArguments.new
+ @req_and_opts_and_etc = Super::RegularAndKeywords::RequiredAndOptionalAndPlaceholderArguments.new
end
it 'passes only required regular arguments to the parent when no optional keyword arguments are given' do
@@ -366,7 +337,7 @@ describe "The super keyword" do
describe 'when using splat and keyword arguments' do
before :each do
- @all = SuperSpecs::SplatAndKeywords::AllArguments.new
+ @all = Super::SplatAndKeywords::AllArguments.new
end
it 'does not pass any arguments to the parent when none are given' do
diff --git a/spec/ruby/language/symbol_spec.rb b/spec/ruby/language/symbol_spec.rb
index d6a41d3059..90540f7d1d 100644
--- a/spec/ruby/language/symbol_spec.rb
+++ b/spec/ruby/language/symbol_spec.rb
@@ -1,4 +1,4 @@
-require_relative '../spec_helper'
+require File.expand_path('../../spec_helper', __FILE__)
describe "A Symbol literal" do
it "is a ':' followed by any number of valid characters" do
@@ -38,7 +38,7 @@ describe "A Symbol literal" do
it 'inherits the encoding of the magic comment and can have a binary encoding' do
ruby_exe(fixture(__FILE__, "binary_symbol.rb"))
- .should == "[105, 108, 95, 195, 169, 116, 97, 105, 116]\n#{Encoding::BINARY.name}\n"
+ .should == "[105, 108, 95, 195, 169, 116, 97, 105, 116]\nASCII-8BIT\n"
end
it "may contain '::' in the string" do
diff --git a/spec/ruby/language/throw_spec.rb b/spec/ruby/language/throw_spec.rb
index d723843688..92f699350c 100644
--- a/spec/ruby/language/throw_spec.rb
+++ b/spec/ruby/language/throw_spec.rb
@@ -1,4 +1,4 @@
-require_relative '../spec_helper'
+require File.expand_path('../../spec_helper', __FILE__)
describe "The throw keyword" do
it "abandons processing" do
@@ -45,7 +45,7 @@ describe "The throw keyword" do
end
it "does not convert strings to a symbol" do
- -> { catch(:exit) { throw "exit" } }.should raise_error(ArgumentError)
+ lambda { catch(:exit) { throw "exit" } }.should raise_error(ArgumentError)
end
it "unwinds stack from within a method" do
@@ -59,13 +59,13 @@ describe "The throw keyword" do
end
it "unwinds stack from within a lambda" do
- c = -> { throw :foo, :msg }
+ c = lambda { throw :foo, :msg }
catch(:foo) { c.call }.should == :msg
end
it "raises an ArgumentError if outside of scope of a matching catch" do
- -> { throw :test, 5 }.should raise_error(ArgumentError)
- -> { catch(:different) { throw :test, 5 } }.should raise_error(ArgumentError)
+ lambda { throw :test, 5 }.should raise_error(ArgumentError)
+ lambda { catch(:different) { throw :test, 5 } }.should raise_error(ArgumentError)
end
it "raises an UncaughtThrowError if used to exit a thread" do
diff --git a/spec/ruby/language/undef_spec.rb b/spec/ruby/language/undef_spec.rb
index 4e473b803f..9e788f2a09 100644
--- a/spec/ruby/language/undef_spec.rb
+++ b/spec/ruby/language/undef_spec.rb
@@ -1,4 +1,4 @@
-require_relative '../spec_helper'
+require File.expand_path('../../spec_helper', __FILE__)
describe "The undef keyword" do
describe "undefines a method" do
@@ -14,35 +14,35 @@ describe "The undef keyword" do
@undef_class.class_eval do
undef meth
end
- -> { @obj.meth(5) }.should raise_error(NoMethodError)
+ lambda { @obj.meth(5) }.should raise_error(NoMethodError)
end
it "with a simple symbol" do
@undef_class.class_eval do
undef :meth
end
- -> { @obj.meth(5) }.should raise_error(NoMethodError)
+ lambda { @obj.meth(5) }.should raise_error(NoMethodError)
end
it "with a single quoted symbol" do
@undef_class.class_eval do
undef :'meth'
end
- -> { @obj.meth(5) }.should raise_error(NoMethodError)
+ lambda { @obj.meth(5) }.should raise_error(NoMethodError)
end
it "with a double quoted symbol" do
@undef_class.class_eval do
undef :"meth"
end
- -> { @obj.meth(5) }.should raise_error(NoMethodError)
+ lambda { @obj.meth(5) }.should raise_error(NoMethodError)
end
it "with a interpolated symbol" do
@undef_class.class_eval do
undef :"#{'meth'}"
end
- -> { @obj.meth(5) }.should raise_error(NoMethodError)
+ lambda { @obj.meth(5) }.should raise_error(NoMethodError)
end
end
@@ -61,7 +61,7 @@ describe "The undef keyword" do
it "raises a NameError when passed a missing name" do
Class.new do
- -> {
+ lambda {
undef not_exist
}.should raise_error(NameError) { |e|
# a NameError and not a NoMethodError
diff --git a/spec/ruby/language/unless_spec.rb b/spec/ruby/language/unless_spec.rb
index 98acdc083b..681f0adfdd 100644
--- a/spec/ruby/language/unless_spec.rb
+++ b/spec/ruby/language/unless_spec.rb
@@ -1,4 +1,4 @@
-require_relative '../spec_helper'
+require File.expand_path('../../spec_helper', __FILE__)
describe "The unless expression" do
it "evaluates the unless body when the expression is false" do
diff --git a/spec/ruby/language/until_spec.rb b/spec/ruby/language/until_spec.rb
index 78c289ff56..08898644ce 100644
--- a/spec/ruby/language/until_spec.rb
+++ b/spec/ruby/language/until_spec.rb
@@ -1,4 +1,4 @@
-require_relative '../spec_helper'
+require File.expand_path('../../spec_helper', __FILE__)
# until bool-expr [do]
# body
@@ -220,7 +220,7 @@ describe "The until modifier with begin .. end block" do
a.should == [0, 1, 2, 4]
end
- it "restart the current iteration without reevaluating condition with redo" do
+ it "restart the current iteration without reevaluting condition with redo" do
a = []
i = 0
j = 0
diff --git a/spec/ruby/language/variables_spec.rb b/spec/ruby/language/variables_spec.rb
index 868603eb88..81ba54840a 100644
--- a/spec/ruby/language/variables_spec.rb
+++ b/spec/ruby/language/variables_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../spec_helper'
-require_relative 'fixtures/variables'
+require File.expand_path('../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/variables', __FILE__)
describe "Multiple assignment" do
context "with a single RHS value" do
@@ -46,7 +46,7 @@ describe "Multiple assignment" do
x = mock("multi-assign single RHS")
x.should_receive(:to_ary).and_return(1)
- -> { a, b, c = x }.should raise_error(TypeError)
+ lambda { a, b, c = x }.should raise_error(TypeError)
end
it "does not call #to_a to convert an Object RHS when assigning a simple MLHS" do
@@ -127,7 +127,7 @@ describe "Multiple assignment" do
x = mock("multi-assign splat")
x.should_receive(:to_ary).and_return(1)
- -> { *a = x }.should raise_error(TypeError)
+ lambda { *a = x }.should raise_error(TypeError)
end
it "does not call #to_ary on an Array subclass" do
@@ -160,7 +160,7 @@ describe "Multiple assignment" do
x = mock("multi-assign splat")
x.should_receive(:to_ary).and_return(1)
- -> { a, *b, c = x }.should raise_error(TypeError)
+ lambda { a, *b, c = x }.should raise_error(TypeError)
end
it "does not call #to_a to convert an Object RHS with a MLHS" do
@@ -256,7 +256,7 @@ describe "Multiple assignment" do
x = mock("multi-assign attributes")
x.should_receive(:m).and_return(y)
- -> { a, b = x.m }.should raise_error(TypeError)
+ lambda { a, b = x.m }.should raise_error(TypeError)
end
it "assigns values from a RHS method call with receiver and arguments" do
@@ -407,7 +407,7 @@ describe "Multiple assignment" do
x = mock("multi-assign RHS splat")
x.should_receive(:to_a).and_return(1)
- -> { *a = *x }.should raise_error(TypeError)
+ lambda { *a = *x }.should raise_error(TypeError)
end
it "does not call #to_ary to convert an Object RHS with a single splat LHS" do
@@ -453,7 +453,7 @@ describe "Multiple assignment" do
x = mock("multi-assign splat")
x.should_receive(:to_a).and_return(1)
- -> { a = *x }.should raise_error(TypeError)
+ lambda { a = *x }.should raise_error(TypeError)
end
it "calls #to_a to convert an Object splat RHS when assigned to a simple MLHS" do
@@ -468,7 +468,7 @@ describe "Multiple assignment" do
x = mock("multi-assign splat")
x.should_receive(:to_a).and_return(1)
- -> { a, b, c = *x }.should raise_error(TypeError)
+ lambda { a, b, c = *x }.should raise_error(TypeError)
end
it "does not call #to_ary to convert an Object splat RHS when assigned to a simple MLHS" do
@@ -491,7 +491,7 @@ describe "Multiple assignment" do
x = mock("multi-assign splat")
x.should_receive(:to_a).and_return(1)
- -> { a, *b, c = *x }.should raise_error(TypeError)
+ lambda { a, *b, c = *x }.should raise_error(TypeError)
end
it "does not call #to_ary to convert an Object RHS with a MLHS" do
@@ -569,7 +569,7 @@ describe "Multiple assignment" do
x = mock("multi-assign splat MRHS")
x.should_receive(:to_a).and_return(1)
- -> { a, *b = 1, *x }.should raise_error(TypeError)
+ lambda { a, *b = 1, *x }.should raise_error(TypeError)
end
it "does not call #to_ary to convert a splatted Object as part of a MRHS with a splat MRHS" do
@@ -592,7 +592,7 @@ describe "Multiple assignment" do
x = mock("multi-assign splat MRHS")
x.should_receive(:to_a).and_return(1)
- -> { a, *b = *x, 1 }.should raise_error(TypeError)
+ lambda { a, *b = *x, 1 }.should raise_error(TypeError)
end
it "does not call #to_ary to convert a splatted Object with a splat MRHS" do
@@ -641,7 +641,7 @@ describe "Multiple assignment" do
x = mock("multi-assign mixed RHS")
x.should_receive(:to_ary).and_return(x)
- -> { a, (b, c), d = 1, x, 3, 4 }.should raise_error(TypeError)
+ lambda { a, (b, c), d = 1, x, 3, 4 }.should raise_error(TypeError)
end
it "calls #to_a to convert a splatted Object value in a MRHS" do
@@ -665,7 +665,7 @@ describe "Multiple assignment" do
x = mock("multi-assign mixed splatted RHS")
x.should_receive(:to_ary).and_return(x)
- -> { a, *b, (c, d) = 1, 2, 3, *x }.should raise_error(TypeError)
+ lambda { a, *b, (c, d) = 1, 2, 3, *x }.should raise_error(TypeError)
end
it "does not call #to_ary to convert an Object when the position receiving the value is a simple variable" do
@@ -758,31 +758,3 @@ describe "A local variable assigned only within a conditional block" do
end
end
end
-
-describe 'Local variable shadowing' do
- ruby_version_is ""..."2.6" do
- it "leads to warning in verbose mode" do
- -> do
- eval <<-CODE
- a = [1, 2, 3]
- a.each { |a| a = 3 }
- CODE
- end.should complain(/shadowing outer local variable/, verbose: true)
- end
- end
-
- ruby_version_is "2.6" do
- it "does not warn in verbose mode" do
- result = nil
-
- -> do
- eval <<-CODE
- a = [1, 2, 3]
- result = a.map { |a| a = 3 }
- CODE
- end.should_not complain(verbose: true)
-
- result.should == [3, 3, 3]
- end
- end
-end
diff --git a/spec/ruby/language/while_spec.rb b/spec/ruby/language/while_spec.rb
index e172453ca6..00e948e41f 100644
--- a/spec/ruby/language/while_spec.rb
+++ b/spec/ruby/language/while_spec.rb
@@ -1,4 +1,4 @@
-require_relative '../spec_helper'
+require File.expand_path('../../spec_helper', __FILE__)
# while bool-expr [do]
# body
@@ -330,7 +330,7 @@ describe "The while modifier with begin .. end block" do
a.should == [0, 1, 2, 4]
end
- it "restarts the current iteration without reevaluating condition with redo" do
+ it "restarts the current iteration without reevaluting condition with redo" do
a = []
i = 0
j = 0
diff --git a/spec/ruby/language/yield_spec.rb b/spec/ruby/language/yield_spec.rb
index 5fad7cb176..663110cbe6 100644
--- a/spec/ruby/language/yield_spec.rb
+++ b/spec/ruby/language/yield_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../spec_helper'
-require_relative 'fixtures/yield'
+require File.expand_path('../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/yield', __FILE__)
# Note that these specs use blocks defined as { |*a| ... } to capture the
# arguments with which the block is invoked. This is slightly confusing
@@ -13,22 +13,18 @@ describe "The yield call" do
describe "taking no arguments" do
it "raises a LocalJumpError when the method is not passed a block" do
- -> { @y.z }.should raise_error(LocalJumpError)
+ lambda { @y.z }.should raise_error(LocalJumpError)
end
it "ignores assignment to the explicit block argument and calls the passed block" do
@y.ze { 42 }.should == 42
end
-
- it "does not pass a named block to the block being yielded to" do
- @y.z() { |&block| block == nil }.should == true
- end
end
describe "taking a single argument" do
describe "when no block is given" do
it "raises a LocalJumpError" do
- -> { @y.s(1) }.should raise_error(LocalJumpError)
+ lambda { @y.s(1) }.should raise_error(LocalJumpError)
end
end
@@ -52,38 +48,40 @@ describe "The yield call" do
describe "yielding to a lambda" do
it "passes an empty Array when the argument is an empty Array" do
- @y.s([], &-> *a { a }).should == [[]]
+ @y.s([], &lambda { |*a| a }).should == [[]]
end
it "passes nil as a value" do
- @y.s(nil, &-> *a { a }).should == [nil]
+ @y.s(nil, &lambda { |*a| a }).should == [nil]
end
it "passes a single value" do
- @y.s(1, &-> *a { a }).should == [1]
+ @y.s(1, &lambda { |*a| a }).should == [1]
end
it "passes a single, multi-value Array" do
- @y.s([1, 2, 3], &-> *a { a }).should == [[1, 2, 3]]
+ @y.s([1, 2, 3], &lambda { |*a| a }).should == [[1, 2, 3]]
end
it "raises an ArgumentError if too few arguments are passed" do
- -> {
- @y.s(1, &-> a, b { [a,b] })
+ lambda {
+ @y.s(1, &lambda { |a,b| [a,b] })
}.should raise_error(ArgumentError)
end
- it "should not destructure an Array into multiple arguments" do
- -> {
- @y.s([1, 2], &-> a, b { [a,b] })
- }.should raise_error(ArgumentError)
+ ruby_bug "#12705", "2.2"..."2.5" do
+ it "should not destructure an Array into multiple arguments" do
+ lambda {
+ @y.s([1, 2], &lambda { |a,b| [a,b] })
+ }.should raise_error(ArgumentError)
+ end
end
end
end
describe "taking multiple arguments" do
it "raises a LocalJumpError when the method is not passed a block" do
- -> { @y.m(1, 2, 3) }.should raise_error(LocalJumpError)
+ lambda { @y.m(1, 2, 3) }.should raise_error(LocalJumpError)
end
it "passes the arguments to the block" do
@@ -95,21 +93,21 @@ describe "The yield call" do
end
it "raises an ArgumentError if too many arguments are passed to a lambda" do
- -> {
- @y.m(1, 2, 3, &-> a { })
+ lambda {
+ @y.m(1, 2, 3, &lambda { |a| })
}.should raise_error(ArgumentError)
end
it "raises an ArgumentError if too few arguments are passed to a lambda" do
- -> {
- @y.m(1, 2, 3, &-> a, b, c, d { })
+ lambda {
+ @y.m(1, 2, 3, &lambda { |a,b,c,d| })
}.should raise_error(ArgumentError)
end
end
describe "taking a single splatted argument" do
it "raises a LocalJumpError when the method is not passed a block" do
- -> { @y.r(0) }.should raise_error(LocalJumpError)
+ lambda { @y.r(0) }.should raise_error(LocalJumpError)
end
it "passes a single value" do
@@ -141,7 +139,7 @@ describe "The yield call" do
describe "taking multiple arguments with a splat" do
it "raises a LocalJumpError when the method is not passed a block" do
- -> { @y.rs(1, 2, [3, 4]) }.should raise_error(LocalJumpError)
+ lambda { @y.rs(1, 2, [3, 4]) }.should raise_error(LocalJumpError)
end
it "passes the arguments to the block" do
@@ -166,7 +164,7 @@ describe "The yield call" do
describe "taking matching arguments with splats and post args" do
it "raises a LocalJumpError when the method is not passed a block" do
- -> { @y.rs(1, 2, [3, 4]) }.should raise_error(LocalJumpError)
+ lambda { @y.rs(1, 2, [3, 4]) }.should raise_error(LocalJumpError)
end
it "passes the arguments to the block" do
@@ -174,12 +172,6 @@ describe "The yield call" do
end
end
- describe "taking a splat and a keyword argument" do
- it "passes it as an array of the values and a hash" do
- @y.k([1, 2]) { |*a| a }.should == [1, 2, {:b=>true}]
- end
- end
-
it "uses captured block of a block used in define_method" do
@y.deep(2).should == 4
end