[前][次][番号順一覧][スレッド一覧]

ruby-changes:60977

From: Benoit <ko1@a...>
Date: Sat, 2 May 2020 23:06:19 +0900 (JST)
Subject: [ruby-changes:60977] c9213aa864 (master): Update to ruby/spec@d394dfd

https://git.ruby-lang.org/ruby.git/commit/?id=c9213aa864

From c9213aa864fb8527388679c21f1ea8ce129e2f1a Mon Sep 17 00:00:00 2001
From: Benoit Daloze <eregontp@g...>
Date: Sat, 2 May 2020 16:03:14 +0200
Subject: Update to ruby/spec@d394dfd


diff --git a/spec/ruby/core/enumerator/next_spec.rb b/spec/ruby/core/enumerator/next_spec.rb
index 3e9ed8b..a5e01a3 100644
--- a/spec/ruby/core/enumerator/next_spec.rb
+++ b/spec/ruby/core/enumerator/next_spec.rb
@@ -24,4 +24,15 @@ describe "Enumerator#next" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/enumerator/next_spec.rb#L24
     @enum.rewind
     @enum.next.should == 1
   end
+
+  it "restarts the enumerator if an exception terminated a previous iteration" do
+    exception = StandardError.new
+    enum = Enumerator.new do
+      raise exception
+    end
+
+    result = 2.times.map { enum.next rescue $! }
+
+    result.should == [exception, exception]
+  end
 end
diff --git a/spec/ruby/core/exception/key_error_spec.rb b/spec/ruby/core/exception/key_error_spec.rb
index ad28027..71bf2b4 100644
--- a/spec/ruby/core/exception/key_error_spec.rb
+++ b/spec/ruby/core/exception/key_error_spec.rb
@@ -10,6 +10,12 @@ describe "KeyError" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/exception/key_error_spec.rb#L10
 
       error.receiver.should == receiver
       error.key.should == key
+
+      error = KeyError.new("message", receiver: receiver, key: key)
+
+      error.message.should == "message"
+      error.receiver.should == receiver
+      error.key.should == key
     end
   end
 end
diff --git a/spec/ruby/core/file/join_spec.rb b/spec/ruby/core/file/join_spec.rb
index f1eab02..0feedba 100644
--- a/spec/ruby/core/file/join_spec.rb
+++ b/spec/ruby/core/file/join_spec.rb
@@ -136,4 +136,13 @@ describe "File.join" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/file/join_spec.rb#L136
     File.join(bin).should == "bin"
     File.join("usr", bin).should == "usr/bin"
   end
+
+  it "raises errors for null bytes" do
+    -> { File.join("\x00x", "metadata.gz") }.should raise_error(ArgumentError) { |e|
+      e.message.should == 'string contains null byte'
+    }
+    -> { File.join("metadata.gz", "\x00x") }.should raise_error(ArgumentError) { |e|
+      e.message.should == 'string contains null byte'
+    }
+  end
 end
diff --git a/spec/ruby/core/file/stat_spec.rb b/spec/ruby/core/file/stat_spec.rb
index 76b0bec..275eae3 100644
--- a/spec/ruby/core/file/stat_spec.rb
+++ b/spec/ruby/core/file/stat_spec.rb
@@ -43,10 +43,11 @@ platform_is_not :windows do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/file/stat_spec.rb#L43
     end
 
     it "returns an error when given missing non-ASCII path" do
-      missing_path = "/missingfilepath\xE3E4".force_encoding("ASCII-8BIT")
+      missing_path = "/missingfilepath\xE3E4".b
       -> {
         File.stat(missing_path)
-      }.should raise_error(Errno::ENOENT) { |e|
+      }.should raise_error(SystemCallError) { |e|
+        [Errno::ENOENT, Errno::EILSEQ].should include(e.class)
         e.message.should include(missing_path)
       }
     end
diff --git a/spec/ruby/core/io/copy_stream_spec.rb b/spec/ruby/core/io/copy_stream_spec.rb
index c541e96..df9c5c7 100644
--- a/spec/ruby/core/io/copy_stream_spec.rb
+++ b/spec/ruby/core/io/copy_stream_spec.rb
@@ -279,4 +279,44 @@ describe "IO.copy_stream" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/io/copy_stream_spec.rb#L279
     end
 
   end
+
+
+  describe "with a destination that does partial reads" do
+    before do
+      @from_out, @from_in = IO.pipe
+      @to_out, @to_in = IO.pipe
+    end
+
+    after do
+      [@from_out, @from_in, @to_out, @to_in].each {|io| io.close rescue nil}
+    end
+
+    it "calls #write repeatedly on the destination Object" do
+      @from_in.write "1234"
+      @from_in.close
+
+      th = Thread.new do
+        IO.copy_stream(@from_out, @to_in)
+      end
+
+      copied = ""
+      4.times do
+        copied += @to_out.read(1)
+      end
+
+      th.join
+
+      copied.should == "1234"
+    end
+
+  end
+end
+
+describe "IO.copy_stream" do
+  it "does not use buffering when writing to STDOUT" do
+    IO.popen([*ruby_exe, fixture(__FILE__ , "copy_in_out.rb")], "r+") do |io|
+      io.write("bar")
+      io.read(3).should == "bar"
+    end
+  end
 end
diff --git a/spec/ruby/core/io/fixtures/classes.rb b/spec/ruby/core/io/fixtures/classes.rb
index 460dd62..5cc42c9 100644
--- a/spec/ruby/core/io/fixtures/classes.rb
+++ b/spec/ruby/core/io/fixtures/classes.rb
@@ -164,7 +164,7 @@ module IOSpecs https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/io/fixtures/classes.rb#L164
       @io = io
     end
 
-    def read(size, buf=nil)
+    def read(size, buf)
       @io.read size, buf
     end
 
@@ -178,7 +178,7 @@ module IOSpecs https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/io/fixtures/classes.rb#L178
       @io = io
     end
 
-    def readpartial(size, buf=nil)
+    def readpartial(size, buf)
       @io.readpartial size, buf
     end
 
diff --git a/spec/ruby/core/io/fixtures/copy_in_out.rb b/spec/ruby/core/io/fixtures/copy_in_out.rb
new file mode 100644
index 0000000..b9d4085
--- /dev/null
+++ b/spec/ruby/core/io/fixtures/copy_in_out.rb
@@ -0,0 +1,2 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/io/fixtures/copy_in_out.rb#L1
+STDOUT.sync = false
+IO.copy_stream(STDIN, STDOUT)
diff --git a/spec/ruby/core/kernel/require_relative_spec.rb b/spec/ruby/core/kernel/require_relative_spec.rb
index b292a46..d4146eb 100644
--- a/spec/ruby/core/kernel/require_relative_spec.rb
+++ b/spec/ruby/core/kernel/require_relative_spec.rb
@@ -90,6 +90,16 @@ describe "Kernel#require_relative with a relative path" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/kernel/require_relative_spec.rb#L90
     ScratchPad.recorded.should == []
   end
 
+  it "raises a LoadError that includes the missing path" do
+    missing_path = "#{@dir}/nonexistent.rb"
+    expanded_missing_path = File.expand_path(missing_path, File.dirname(__FILE__))
+    -> { require_relative(missing_path) }.should raise_error(LoadError) { |e|
+      e.message.should include(expanded_missing_path)
+      e.path.should == expanded_missing_path
+    }
+    ScratchPad.recorded.should == []
+  end
+
   it "raises a LoadError if basepath does not exist" do
     -> { eval("require_relative('#{@dir}/nonexistent.rb')") }.should raise_error(LoadError)
   end
diff --git a/spec/ruby/core/module/using_spec.rb b/spec/ruby/core/module/using_spec.rb
index 533d87d..4781b99 100644
--- a/spec/ruby/core/module/using_spec.rb
+++ b/spec/ruby/core/module/using_spec.rb
@@ -243,6 +243,96 @@ describe "Module#using" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/module/using_spec.rb#L243
       mod.call_foo(c).should == "foo from refinement"
     end
 
+    it "is active for module defined via Module.new {}" do
+      refinement = Module.new do
+        refine Integer do
+          def foo; "foo from refinement"; end
+        end
+      end
+
+      result = nil
+
+      Module.new do
+        using refinement
+
+        Module.new do
+          result = 1.foo
+        end
+      end
+
+      result.should == "foo from refinement"
+    end
+
+    it "is active for class defined via Class.new {}" do
+      refinement = Module.new do
+        refine Integer do
+          def foo; "foo from refinement"; end
+        end
+      end
+
+      result = nil
+
+      Module.new do
+        using refinement
+
+        Class.new do
+          result = 1.foo
+        end
+      end
+
+      result.should == "foo from refinement"
+    end
+
+    it "is active for block called via instance_exec" do
+      refinement = Module.new do
+        refine Integer do
+          def foo; "foo from refinement"; end
+        end
+      end
+
+      c = Class.new do
+        using refinement
+
+        def abc
+          block = -> {
+            1.foo
+          }
+
+          self.instance_exec(&block)
+        end
+      end
+
+      c.new.abc.should == "foo from refinement"
+    end
+
+    it "is active for block called via instance_eval" do
+      refinement = Module.new do
+        refine String do
+          def foo; "foo from refinement"; end
+        end
+      end
+
+      c = Class.new do
+        using refinement
+
+        def initialize
+          @a = "1703"
+
+          @a.instance_eval do
+            def abc
+              "#{self}: #{self.foo}"
+            end
+          end
+        end
+
+        def abc
+          @a.abc
+        end
+      end
+
+      c.new.abc.should == "1703: foo from refinement"
+    end
+
     it "is not active if `using` call is not evaluated" do
       result = nil
 
diff --git a/spec/ruby/core/objectspace/weakmap/each_key_spec.rb b/spec/ruby/core/objectspace/weakmap/each_key_spec.rb
new file mode 100644
index 0000000..df971de
--- /dev/null
+++ b/spec/ruby/core/objectspace/weakmap/each_key_spec.rb
@@ -0,0 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/objectspace/weakmap/each_key_spec.rb#L1
+require_relative '../../../spec_helper'
+require_relative 'shared/members'
+require_relative 'shared/each'
+
+describe "ObjectSpace::WeakMap#each_key" do
+  it_behaves_like :weakmap_members, -> map { a = []; map.each_key{ |k| a << k }; a }, %w[A B]
+end
+
+describe "ObjectSpace::WeakMap#each_key" do
+  it_behaves_like :weakmap_each, :each_key
+end
diff --git a/spec/ruby/core/objectspace/weakmap/each_pair_spec.rb b/spec/ruby/core/objectspace/weakmap/each_pair_spec.rb
new file mode 100644
index 0000000..ea29edb
--- /dev/null
+++ b/spec/ruby/core/objectspace/weakmap/each_pair_spec.rb
@@ -0,0 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/objectspace/weakmap/each_pair_spec.rb#L1
+require_relative '../../../spec_helper'
+require_relative 'shared/members'
+require_relative 'shared/each'
+
+describe "ObjectSpace::WeakMap#each_pair" do
+  it_behaves_like :weakmap_members, -> map { a = []; map.each_pair{ |k,v| a << "#{k}#{v}" }; a }, %w[Ax By]
+end
+
+describe "ObjectSpace::Wea (... truncated)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]