diff options
author | Benoit Daloze <[email protected]> | 2022-06-26 14:50:14 +0200 |
---|---|---|
committer | Benoit Daloze <[email protected]> | 2022-06-26 14:50:14 +0200 |
commit | d3d5ef0cca160fca538c7f556c5a6e08df5847e6 (patch) | |
tree | 57358b4b9cdd6f429d0383005ac393cb74dd3bff /spec/ruby/language/predefined_spec.rb | |
parent | f616e816372d14e605879d2e43c7fbdda29ef837 (diff) |
Update to ruby/spec@ab32a1a
Diffstat (limited to 'spec/ruby/language/predefined_spec.rb')
-rw-r--r-- | spec/ruby/language/predefined_spec.rb | 66 |
1 files changed, 65 insertions, 1 deletions
diff --git a/spec/ruby/language/predefined_spec.rb b/spec/ruby/language/predefined_spec.rb index b5eda7f789..87385a29e5 100644 --- a/spec/ruby/language/predefined_spec.rb +++ b/spec/ruby/language/predefined_spec.rb @@ -570,7 +570,6 @@ describe "Predefined global $/" do ($/ = "xyz").should == "xyz" end - it "changes $-0" do $/ = "xyz" $-0.should equal($/) @@ -641,6 +640,45 @@ describe "Predefined global $-0" do end end +describe "Predefined global $\\" do + before :each do + @verbose, $VERBOSE = $VERBOSE, nil + @dollar_backslash = $\ + end + + after :each do + $\ = @dollar_backslash + $VERBOSE = @verbose + end + + it "can be assigned a String" do + str = "abc" + $\ = str + $\.should equal(str) + end + + it "can be assigned nil" do + $\ = nil + $\.should be_nil + end + + it "returns the value assigned" do + ($\ = "xyz").should == "xyz" + end + + it "does not call #to_str to convert the object to a String" do + obj = mock("$\\ value") + obj.should_not_receive(:to_str) + + -> { $\ = obj }.should raise_error(TypeError) + end + + it "raises a TypeError if assigned not String" do + -> { $\ = 1 }.should raise_error(TypeError) + -> { $\ = true }.should raise_error(TypeError) + end +end + describe "Predefined global $," do after :each do $, = nil @@ -1340,3 +1378,29 @@ describe "$LOAD_PATH.resolve_feature_path" do end end end + +# Some other pre-defined global variables + +describe "Predefined global $=" do + before :each do + @verbose, $VERBOSE = $VERBOSE, nil + @dollar_assign = $= + end + + after :each do + $= = @dollar_assign + $VERBOSE = @verbose + end + + it "warns when accessed" do + -> { a = $= }.should complain(/is no longer effective/) + end + + it "warns when assigned" do + -> { $= = "_" }.should complain(/is no longer effective/) + end + + it "returns the value assigned" do + ($= = "xyz").should == "xyz" + end +end |