diff options
author | Benoit Daloze <eregontp@gmail.com> | 2021-09-07 19:01:07 +0200 |
---|---|---|
committer | Benoit Daloze <eregontp@gmail.com> | 2021-09-07 19:01:07 +0200 |
commit | 258661409e9e3fd470f006975ded872778aad4f4 (patch) | |
tree | 4cd23fe290feb50f4d41349013dbb41bdf12117f /spec/ruby/core | |
parent | a375640ea561d1f7c4d2d89839007b3a973a04e0 (diff) | |
download | ruby-258661409e9e3fd470f006975ded872778aad4f4.tar.gz |
Update to ruby/spec@b1e93a2
Diffstat (limited to 'spec/ruby/core')
-rw-r--r-- | spec/ruby/core/array/intersect_spec.rb | 17 | ||||
-rw-r--r-- | spec/ruby/core/dir/fixtures/common.rb | 1 | ||||
-rw-r--r-- | spec/ruby/core/dir/glob_spec.rb | 2 | ||||
-rw-r--r-- | spec/ruby/core/dir/shared/glob.rb | 5 | ||||
-rw-r--r-- | spec/ruby/core/enumerable/tally_spec.rb | 2 | ||||
-rw-r--r-- | spec/ruby/core/float/comparison_spec.rb | 3 | ||||
-rw-r--r-- | spec/ruby/core/kernel/nil_spec.rb | 10 | ||||
-rw-r--r-- | spec/ruby/core/module/define_method_spec.rb | 51 | ||||
-rw-r--r-- | spec/ruby/core/process/spawn_spec.rb | 20 | ||||
-rw-r--r-- | spec/ruby/core/rational/rational_spec.rb | 4 | ||||
-rw-r--r-- | spec/ruby/core/tracepoint/inspect_spec.rb | 5 |
11 files changed, 114 insertions, 6 deletions
diff --git a/spec/ruby/core/array/intersect_spec.rb b/spec/ruby/core/array/intersect_spec.rb new file mode 100644 index 0000000000..b8c5b1e69a --- /dev/null +++ b/spec/ruby/core/array/intersect_spec.rb @@ -0,0 +1,17 @@ +require_relative '../../spec_helper' + +describe 'Array#intersect?' do + ruby_version_is '3.1' do # https://bugs.ruby-lang.org/issues/15198 + describe 'when at least one element in two Arrays is the same' do + it 'returns true' do + [1, 2].intersect?([2, 3]).should == true + end + end + + describe 'when there are no elements in common between two Arrays' do + it 'returns false' do + [1, 2].intersect?([3, 4]).should == false + end + end + end +end diff --git a/spec/ruby/core/dir/fixtures/common.rb b/spec/ruby/core/dir/fixtures/common.rb index a1ea3db215..1a197d7a97 100644 --- a/spec/ruby/core/dir/fixtures/common.rb +++ b/spec/ruby/core/dir/fixtures/common.rb @@ -81,6 +81,7 @@ module DirSpecs special/} special/test{1}/file[1] + special/{}/special ] platform_is_not :windows do diff --git a/spec/ruby/core/dir/glob_spec.rb b/spec/ruby/core/dir/glob_spec.rb index 6533c9b65a..295a7ab920 100644 --- a/spec/ruby/core/dir/glob_spec.rb +++ b/spec/ruby/core/dir/glob_spec.rb @@ -80,6 +80,7 @@ describe "Dir.glob" do nested/.dotsubir/ special/ special/test{1}/ + special/{}/ subdir_one/ subdir_two/ ] @@ -130,6 +131,7 @@ describe "Dir.glob" do ./nested/.dotsubir/ ./special/ ./special/test{1}/ + ./special/{}/ ./subdir_one/ ./subdir_two/ ] diff --git a/spec/ruby/core/dir/shared/glob.rb b/spec/ruby/core/dir/shared/glob.rb index ae5c2a114b..89d6b90283 100644 --- a/spec/ruby/core/dir/shared/glob.rb +++ b/spec/ruby/core/dir/shared/glob.rb @@ -64,6 +64,10 @@ describe :dir_glob, shared: true do Dir.send(@method, 'special/+').should == ['special/+'] end + it "matches directories with special characters when escaped" do + Dir.send(@method, 'special/\{}/special').should == ["special/{}/special"] + end + platform_is_not :windows do it "matches regexp special *" do Dir.send(@method, 'special/\*').should == ['special/*'] @@ -191,6 +195,7 @@ describe :dir_glob, shared: true do nested/ special/ special/test{1}/ + special/{}/ subdir_one/ subdir_two/ ] diff --git a/spec/ruby/core/enumerable/tally_spec.rb b/spec/ruby/core/enumerable/tally_spec.rb index c23ea11697..92aac507ff 100644 --- a/spec/ruby/core/enumerable/tally_spec.rb +++ b/spec/ruby/core/enumerable/tally_spec.rb @@ -51,7 +51,7 @@ ruby_version_is "3.1" do enum.tally(hash).should equal(hash) end - it "raises a FrozenError and does not udpate the given hash when the hash is frozen" do + it "raises a FrozenError and does not update the given hash when the hash is frozen" do enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz') hash = { 'foo' => 1 }.freeze -> { enum.tally(hash) }.should raise_error(FrozenError) diff --git a/spec/ruby/core/float/comparison_spec.rb b/spec/ruby/core/float/comparison_spec.rb index e367198903..a46841ffbf 100644 --- a/spec/ruby/core/float/comparison_spec.rb +++ b/spec/ruby/core/float/comparison_spec.rb @@ -14,6 +14,9 @@ describe "Float#<=>" do it "returns nil when the given argument is not a Float" do (1.0 <=> "1").should be_nil + (1.0 <=> "1".freeze).should be_nil + (1.0 <=> :one).should be_nil + (1.0 <=> true).should be_nil end it "compares using #coerce when argument is not a Float" do diff --git a/spec/ruby/core/kernel/nil_spec.rb b/spec/ruby/core/kernel/nil_spec.rb index b63705f7bc..7418245f26 100644 --- a/spec/ruby/core/kernel/nil_spec.rb +++ b/spec/ruby/core/kernel/nil_spec.rb @@ -1,6 +1,12 @@ require_relative '../../spec_helper' require_relative 'fixtures/classes' -describe "Kernel#nil?" do - it "needs to be reviewed for spec completeness" +describe 'Kernel#nil?' do + it 'returns false' do + Object.should_not.nil? + Object.new.should_not.nil? + ''.should_not.nil? + [].should_not.nil? + {}.should_not.nil? + end end diff --git a/spec/ruby/core/module/define_method_spec.rb b/spec/ruby/core/module/define_method_spec.rb index 0cb2ab140c..c65b30de24 100644 --- a/spec/ruby/core/module/define_method_spec.rb +++ b/spec/ruby/core/module/define_method_spec.rb @@ -350,6 +350,14 @@ describe "Module#define_method" do object2.other_cool_method.should == "data is foo" end + it "accepts a proc from a Symbol" do + symbol_proc = :+.to_proc + klass = Class.new do + define_method :foo, &symbol_proc + end + klass.new.foo(1, 2).should == 3 + end + it "maintains the Proc's scope" do class DefineMethodByProcClass in_scope = true @@ -715,3 +723,46 @@ describe "Method#define_method when passed a Proc object" do end end end + +describe "Method#define_method when passed a block" do + describe "behaves exactly like a lambda" do + it "for return" do + Class.new do + define_method(:foo) do + return 42 + end + end.new.foo.should == 42 + end + + it "for break" do + Class.new do + define_method(:foo) do + break 42 + end + end.new.foo.should == 42 + end + + it "for next" do + Class.new do + define_method(:foo) do + next 42 + end + end.new.foo.should == 42 + end + + it "for redo" do + Class.new do + result = [] + define_method(:foo) do + if result.empty? + result << :first + redo + else + result << :second + result + end + end + end.new.foo.should == [:first, :second] + end + end +end diff --git a/spec/ruby/core/process/spawn_spec.rb b/spec/ruby/core/process/spawn_spec.rb index 56e02ff38a..6be3f41a87 100644 --- a/spec/ruby/core/process/spawn_spec.rb +++ b/spec/ruby/core/process/spawn_spec.rb @@ -212,6 +212,26 @@ describe "Process.spawn" do end.should output_to_fd("nil\n") end + platform_is_not :windows do + it "uses the passed env['PATH'] to search the executable" do + dir = tmp("spawn_path_dir") + mkdir_p dir + begin + exe = 'process-spawn-executable-in-path' + path = "#{dir}/#{exe}" + File.write(path, "#!/bin/sh\necho $1") + File.chmod(0755, path) + + env = { "PATH" => "#{dir}#{File::PATH_SEPARATOR}#{ENV['PATH']}" } + Process.wait Process.spawn(env, exe, 'OK', out: @name) + $?.should.success? + File.read(@name).should == "OK\n" + ensure + rm_r dir + end + end + end + it "calls #to_hash to convert the environment" do o = mock("to_hash") o.should_receive(:to_hash).and_return({"FOO" => "BAR"}) diff --git a/spec/ruby/core/rational/rational_spec.rb b/spec/ruby/core/rational/rational_spec.rb index 704e49354e..482deab38d 100644 --- a/spec/ruby/core/rational/rational_spec.rb +++ b/spec/ruby/core/rational/rational_spec.rb @@ -4,4 +4,8 @@ describe "Rational" do it "includes Comparable" do Rational.include?(Comparable).should == true end + + it "does not respond to new" do + -> { Rational.new(1) }.should raise_error(NoMethodError) + end end diff --git a/spec/ruby/core/tracepoint/inspect_spec.rb b/spec/ruby/core/tracepoint/inspect_spec.rb index 67e2ad1494..b9d7f35c32 100644 --- a/spec/ruby/core/tracepoint/inspect_spec.rb +++ b/spec/ruby/core/tracepoint/inspect_spec.rb @@ -64,13 +64,12 @@ describe 'TracePoint#inspect' do it 'returns a String showing the event, method, path and line for a :c_call event' do inspect = nil - line = nil - tp = TracePoint.new(:c_call) { |tp| + tracepoint = TracePoint.new(:c_call) { |tp| next unless TracePointSpec.target_thread? inspect ||= tp.inspect } line = __LINE__ + 2 - tp.enable do + tracepoint.enable do [0, 1].max end |