Skip to content

Commit

Permalink
Update to ruby/spec@9a501a8
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed May 28, 2019
1 parent d070523 commit a66bc2c
Show file tree
Hide file tree
Showing 41 changed files with 699 additions and 639 deletions.
4 changes: 2 additions & 2 deletions spec/ruby/CONTRIBUTING.md
Expand Up @@ -188,7 +188,7 @@ variables from the implementor spec: `@method` and `@object`, which the implemen

Here's an example of a snippet of a shared spec and two specs which integrates it:

``` ruby
```ruby
# core/hash/shared/key.rb
describe :hash_key_p, shared: true do
it "returns true if the key's matching value was false" do
Expand Down Expand Up @@ -216,7 +216,7 @@ Sometimes, shared specs require more context from the implementor class than a s
this by passing a lambda as the method, which will have the scope of the implementor. Here's an example of
how this is used currently:

``` ruby
```ruby
describe :kernel_sprintf, shared: true do
it "raises TypeError exception if cannot convert to Integer" do
-> { @method.call("%b", Object.new) }.should raise_error(TypeError)
Expand Down
4 changes: 4 additions & 0 deletions spec/ruby/core/enumerable/shared/find.rb
Expand Up @@ -49,6 +49,10 @@
@empty.send(@method, fail_proc) {|e| true}.should == "yay"
end

it "ignores the ifnone argument when nil" do
@numerous.send(@method, nil) {|e| false }.should == nil
end

it "passes through the values yielded by #each_with_index" do
[:a, :b].each_with_index.send(@method) { |x, i| ScratchPad << [x, i]; nil }
ScratchPad.recorded.should == [[:a, 0], [:b, 1]]
Expand Down
15 changes: 15 additions & 0 deletions spec/ruby/core/exception/backtrace_spec.rb
Expand Up @@ -65,4 +65,19 @@
e.backtrace[0].should == "backtrace first"
end
end

it "returns the same array after duping" do
begin
raise
rescue RuntimeError => err
bt = err.backtrace
err.dup.backtrace.should equal(bt)

new_bt = ['hi']
err.set_backtrace new_bt

err.backtrace.should == new_bt
err.dup.backtrace.should equal(new_bt)
end
end
end
12 changes: 12 additions & 0 deletions spec/ruby/core/exception/cause_spec.rb
Expand Up @@ -41,4 +41,16 @@
e.cause.should equal(cause)
}
end

it "is not set to the exception itself when it is re-raised" do
-> {
begin
raise RuntimeError
rescue RuntimeError => e
raise e
end
}.should raise_error(RuntimeError) { |e|
e.cause.should == nil
}
end
end
2 changes: 2 additions & 0 deletions spec/ruby/core/file/expand_path_spec.rb
Expand Up @@ -225,6 +225,8 @@
user = ENV.delete("USER")
begin
Etc.getlogin != nil
rescue
false
ensure
ENV["USER"] = user
end
Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/core/hash/constructor_spec.rb
Expand Up @@ -54,7 +54,7 @@
end

ruby_version_is "2.7" do
it "ignores elements that are not arrays" do
it "raises for elements that are not arrays" do
-> {
Hash[[:a]].should == {}
}.should raise_error(ArgumentError)
Expand Down
8 changes: 8 additions & 0 deletions spec/ruby/core/hash/hash_spec.rb
Expand Up @@ -11,6 +11,14 @@
{ 0=>2, 11=>1 }.hash.should == { 11=>1, 0=>2 }.hash
end

it "returns a value in which element values do not cancel each other out" do
{ a: 2, b: 2 }.hash.should_not == { a: 7, b: 7 }.hash
end

it "returns a value in which element keys and values do not cancel each other out" do
{ :a => :a }.hash.should_not == { :b => :b }.hash
end

it "generates a hash for recursive hash structures" do
h = {}
h[:a] = h
Expand Down
18 changes: 18 additions & 0 deletions spec/ruby/core/hash/merge_spec.rb
Expand Up @@ -63,6 +63,24 @@
merge_pairs.should == each_pairs
end

it "preserves the order of merged elements" do
h1 = { 1 => 2, 3 => 4, 5 => 6 }
h2 = { 1 => 7 }
merge_pairs = []
h1.merge(h2).each_pair { |k, v| merge_pairs << [k, v] }
merge_pairs.should == [[1,7], [3, 4], [5, 6]]
end

it "preserves the order of merged elements for large hashes" do
h1 = {}
h2 = {}
merge_pairs = []
expected_pairs = []
(1..100).each { |x| h1[x] = x; h2[101 - x] = x; expected_pairs << [x, 101 - x] }
h1.merge(h2).each_pair { |k, v| merge_pairs << [k, v] }
merge_pairs.should == expected_pairs
end

ruby_version_is "2.6" do
it "accepts multiple hashes" do
result = { a: 1 }.merge({ b: 2 }, { c: 3 }, { d: 4 })
Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/core/kernel/autoload_spec.rb
Expand Up @@ -57,7 +57,7 @@ def check_autoload(const)
end

describe "when Object is frozen" do
it "raises a FrozenError before defining the constant" do
it "raises a #{frozen_error_class} before defining the constant" do
ruby_exe(fixture(__FILE__, "autoload_frozen.rb")).should == "#{frozen_error_class} - nil"
end
end
Expand Down
11 changes: 5 additions & 6 deletions spec/ruby/core/marshal/dump_spec.rb
Expand Up @@ -449,14 +449,13 @@ def obj.foo; end
zone = ":\tzoneI\"\bAST\x06:\x06EF" # Last is 'F' (US-ASCII)
[ "#{base}#{offset}#{zone}", "#{base}#{zone}#{offset}" ].should include(dump)
end

it "dumps the zone, but not the offset if zone is UTC" do
dump = Marshal.dump(@utc)
zone = ":\tzoneI\"\bUTC\x06:\x06EF" # Last is 'F' (US-ASCII)
dump.should == "\x04\bIu:\tTime\r#{@utc_dump}\x06#{zone}"
end
end

it "dumps the zone, but not the offset if zone is UTC" do
dump = Marshal.dump(@utc)
zone = ":\tzoneI\"\bUTC\x06:\x06EF" # Last is 'F' (US-ASCII)
dump.should == "\x04\bIu:\tTime\r#{@utc_dump}\x06#{zone}"
end
end

describe "with an Exception" do
Expand Down
6 changes: 3 additions & 3 deletions spec/ruby/core/module/name_spec.rb
Expand Up @@ -15,13 +15,13 @@
it "is not nil for a nested module created with the module keyword" do
m = Module.new
module m::N; end
m::N.name.should =~ /#<Module:0x[0-9a-f]+>::N/
m::N.name.should =~ /\A#<Module:0x[0-9a-f]+>::N\z/
end

it "changes when the module is reachable through a constant path" do
m = Module.new
module m::N; end
m::N.name.should =~ /#<Module:0x[0-9a-f]+>::N/
m::N.name.should =~ /\A#<Module:0x\h+>::N\z/
ModuleSpecs::Anonymous::WasAnnon = m::N
m::N.name.should == "ModuleSpecs::Anonymous::WasAnnon"
end
Expand All @@ -42,7 +42,7 @@ module ModuleToRemove
module m::Child; end
child = m::Child
m.send(:remove_const, :Child)
child.name.should =~ /#<Module:0x[0-9a-f]+>::Child/
child.name.should =~ /\A#<Module:0x\h+>::Child\z/
end

it "is set when opened with the module keyword" do
Expand Down
11 changes: 11 additions & 0 deletions spec/ruby/core/proc/new_spec.rb
Expand Up @@ -190,6 +190,17 @@ def some_method

prc.call.should == "hello"
end

it "uses the implicit block from an enclosing method when called inside a block" do
def some_method
proc do |&block|
Proc.new
end.call { "failing" }
end
prc = some_method { "hello" }

prc.call.should == "hello"
end
end

ruby_version_is "2.7" do
Expand Down
22 changes: 22 additions & 0 deletions spec/ruby/core/proc/shared/call_arguments.rb
Expand Up @@ -4,4 +4,26 @@
lambda {|&b| b.send(@method)}.send(@method) {1 + 1}.should == 2
proc {|&b| b.send(@method)}.send(@method) {1 + 1}.should == 2
end

it "yields to the block given at declaration and not to the block argument" do
proc_creator = Object.new
def proc_creator.create
Proc.new do |&b|
yield
end
end
a_proc = proc_creator.create { 7 }
a_proc.send(@method) { 3 }.should == 7
end

it "can call its block argument declared with a block argument" do
proc_creator = Object.new
def proc_creator.create(method_name)
Proc.new do |&b|
yield + b.send(method_name)
end
end
a_proc = proc_creator.create(@method) { 7 }
a_proc.call { 3 }.should == 10
end
end
13 changes: 5 additions & 8 deletions spec/ruby/core/regexp/compile_spec.rb
@@ -1,18 +1,15 @@
require_relative '../../spec_helper'
require_relative 'shared/new_ascii'
require_relative 'shared/new_ascii_8bit'
require_relative 'shared/new'

describe "Regexp.compile" do
it_behaves_like :regexp_new_ascii, :compile
it_behaves_like :regexp_new_ascii_8bit, :compile
it_behaves_like :regexp_new, :compile
end

describe "Regexp.compile given a String" do
it_behaves_like :regexp_new_string_ascii, :compile
it_behaves_like :regexp_new_string_ascii_8bit, :compile
it_behaves_like :regexp_new_string, :compile
it_behaves_like :regexp_new_string_binary, :compile
end

describe "Regexp.compile given a Regexp" do
it_behaves_like :regexp_new_regexp_ascii, :compile
it_behaves_like :regexp_new_regexp_ascii_8bit, :compile
it_behaves_like :regexp_new_regexp, :compile
end
13 changes: 5 additions & 8 deletions spec/ruby/core/regexp/new_spec.rb
@@ -1,20 +1,17 @@
require_relative '../../spec_helper'
require_relative 'shared/new_ascii'
require_relative 'shared/new_ascii_8bit'
require_relative 'shared/new'

describe "Regexp.new" do
it_behaves_like :regexp_new_ascii, :new
it_behaves_like :regexp_new_ascii_8bit, :new
it_behaves_like :regexp_new, :new
end

describe "Regexp.new given a String" do
it_behaves_like :regexp_new_string_ascii, :new
it_behaves_like :regexp_new_string_ascii_8bit, :new
it_behaves_like :regexp_new_string, :new
end

describe "Regexp.new given a Regexp" do
it_behaves_like :regexp_new_regexp_ascii, :new
it_behaves_like :regexp_new_regexp_ascii_8bit, :new
it_behaves_like :regexp_new_regexp, :new
it_behaves_like :regexp_new_string_binary, :compile
end

describe "Regexp.new given a Fixnum" do
Expand Down

0 comments on commit a66bc2c

Please sign in to comment.