aboutsummaryrefslogtreecommitdiffstats
path: root/spec/ruby/core
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core')
-rw-r--r--spec/ruby/core/exception/top_level_spec.rb25
-rw-r--r--spec/ruby/core/kernel/freeze_spec.rb8
-rw-r--r--spec/ruby/core/kernel/instance_variables_spec.rb4
-rw-r--r--spec/ruby/core/kernel/shared/require.rb15
-rw-r--r--spec/ruby/core/process/spawn_spec.rb9
-rw-r--r--spec/ruby/core/string/encode_spec.rb31
6 files changed, 86 insertions, 6 deletions
diff --git a/spec/ruby/core/exception/top_level_spec.rb b/spec/ruby/core/exception/top_level_spec.rb
index 96f957411e..97a91b0a58 100644
--- a/spec/ruby/core/exception/top_level_spec.rb
+++ b/spec/ruby/core/exception/top_level_spec.rb
@@ -5,6 +5,31 @@ describe "An Exception reaching the top level" do
ruby_exe('raise "foo"', args: "2>&1").should.include?("in `<main>': foo (RuntimeError)")
end
+ ruby_version_is "2.6" do
+ it "the Exception#cause is printed to STDERR with backtraces" do
+ code = <<-RUBY
+ def raise_cause
+ raise "the cause"
+ end
+ def raise_wrapped
+ raise "wrapped"
+ end
+ begin
+ raise_cause
+ rescue
+ raise_wrapped
+ end
+ RUBY
+ lines = ruby_exe(code, args: "2>&1").lines
+ lines.reject! { |l| l.include?('rescue in') }
+ lines.map! { |l| l.split(':')[2..-1].join(':').chomp }
+ lines.should == ["in `raise_wrapped': wrapped (RuntimeError)",
+ "in `<main>'",
+ "in `raise_cause': the cause (RuntimeError)",
+ "in `<main>'"]
+ end
+ end
+
describe "with a custom backtrace" do
it "is printed on STDERR" do
code = <<-RUBY
diff --git a/spec/ruby/core/kernel/freeze_spec.rb b/spec/ruby/core/kernel/freeze_spec.rb
index e4a01b5df5..fa32d321cf 100644
--- a/spec/ruby/core/kernel/freeze_spec.rb
+++ b/spec/ruby/core/kernel/freeze_spec.rb
@@ -80,4 +80,12 @@ describe "Kernel#freeze" do
o.freeze
-> {o.instance_variable_set(:@foo, 1)}.should raise_error(RuntimeError)
end
+
+ it "freezes an object's singleton class" do
+ o = Object.new
+ c = o.singleton_class
+ c.frozen?.should == false
+ o.freeze
+ c.frozen?.should == true
+ end
end
diff --git a/spec/ruby/core/kernel/instance_variables_spec.rb b/spec/ruby/core/kernel/instance_variables_spec.rb
index b6d6e27772..831f0662a2 100644
--- a/spec/ruby/core/kernel/instance_variables_spec.rb
+++ b/spec/ruby/core/kernel/instance_variables_spec.rb
@@ -4,7 +4,9 @@ require_relative 'fixtures/classes'
describe "Kernel#instance_variables" do
describe "immediate values" do
it "returns an empty array if no instance variables are defined" do
- 0.instance_variables.should == []
+ [0, 0.5, true, false, nil].each do |value|
+ value.instance_variables.should == []
+ end
end
it "returns the correct array if an instance variable is added" do
diff --git a/spec/ruby/core/kernel/shared/require.rb b/spec/ruby/core/kernel/shared/require.rb
index 0e7f8ba665..6c6895e317 100644
--- a/spec/ruby/core/kernel/shared/require.rb
+++ b/spec/ruby/core/kernel/shared/require.rb
@@ -344,6 +344,21 @@ describe :kernel_require, shared: true do
loaded_feature = $LOADED_FEATURES.last
ScratchPad.recorded.should == [loaded_feature]
end
+
+ it "requires only once when a new matching file added to path" do
+ @object.require('load_fixture').should be_true
+ ScratchPad.recorded.should == [:loaded]
+
+ symlink_to_code_dir_two = tmp("codesymlinktwo")
+ File.symlink("#{CODE_LOADING_DIR}/b", symlink_to_code_dir_two)
+ begin
+ $LOAD_PATH.unshift(symlink_to_code_dir_two)
+
+ @object.require('load_fixture').should be_false
+ ensure
+ rm_r symlink_to_code_dir_two
+ end
+ end
end
describe "with symlinks in the required feature and $LOAD_PATH" do
diff --git a/spec/ruby/core/process/spawn_spec.rb b/spec/ruby/core/process/spawn_spec.rb
index 6b08e0227b..8c544daae4 100644
--- a/spec/ruby/core/process/spawn_spec.rb
+++ b/spec/ruby/core/process/spawn_spec.rb
@@ -536,6 +536,15 @@ describe "Process.spawn" do
File.read(@name).should == "glarkbang"
end
+ it "closes STDERR in the child if :err => :close" do
+ File.open(@name, 'w') do |file|
+ -> do
+ code = "begin; STDOUT.puts 'out'; STDERR.puts 'hello'; rescue => e; puts 'rescued'; end"
+ Process.wait Process.spawn(ruby_cmd(code), :out => file, :err => :close)
+ end.should output_to_fd("out\nrescued\n", file)
+ end
+ end
+
# :close_others
platform_is_not :windows do
diff --git a/spec/ruby/core/string/encode_spec.rb b/spec/ruby/core/string/encode_spec.rb
index 04d9db855a..ae641b2110 100644
--- a/spec/ruby/core/string/encode_spec.rb
+++ b/spec/ruby/core/string/encode_spec.rb
@@ -19,13 +19,17 @@ describe "String#encode" do
it "returns a copy when Encoding.default_internal is nil" do
Encoding.default_internal = nil
str = "あ"
- str.encode.should_not equal(str)
+ encoded = str.encode
+ encoded.should_not equal(str)
+ encoded.should == str
end
it "returns a copy for a ASCII-only String when Encoding.default_internal is nil" do
Encoding.default_internal = nil
str = "abc"
- str.encode.should_not equal(str)
+ encoded = str.encode
+ encoded.should_not equal(str)
+ encoded.should == str
end
it "encodes an ascii substring of a binary string to UTF-8" do
@@ -39,7 +43,9 @@ describe "String#encode" do
describe "when passed to encoding" do
it "returns a copy when passed the same encoding as the String" do
str = "あ"
- str.encode(Encoding::UTF_8).should_not equal(str)
+ encoded = str.encode(Encoding::UTF_8)
+ encoded.should_not equal(str)
+ encoded.should == str
end
it "round trips a String" do
@@ -75,6 +81,7 @@ describe "String#encode" do
encoded = str.encode("utf-8", "utf-8")
encoded.should_not equal(str)
+ encoded.should == str.force_encoding("utf-8")
encoded.encoding.should == Encoding::UTF_8
end
@@ -87,14 +94,28 @@ describe "String#encode" do
describe "when passed to, options" do
it "returns a copy when the destination encoding is the same as the String encoding" do
str = "あ"
- str.encode(Encoding::UTF_8, undef: :replace).should_not equal(str)
+ encoded = str.encode(Encoding::UTF_8, undef: :replace)
+ encoded.should_not equal(str)
+ encoded.should == str
end
end
describe "when passed to, from, options" do
it "returns a copy when both encodings are the same" do
str = "あ"
- str.encode("utf-8", "utf-8", invalid: :replace).should_not equal(str)
+ encoded = str.encode("utf-8", "utf-8", invalid: :replace)
+ encoded.should_not equal(str)
+ encoded.should == str
+ end
+
+ it "returns a copy in the destination encoding when both encodings are the same" do
+ str = "あ"
+ str.force_encoding("binary")
+ encoded = str.encode("utf-8", "utf-8", invalid: :replace)
+
+ encoded.should_not equal(str)
+ encoded.should == str.force_encoding("utf-8")
+ encoded.encoding.should == Encoding::UTF_8
end
end
end