Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 6a0bb070a359
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: debc0d175829
Choose a head ref
  • 2 commits
  • 59 files changed
  • 1 contributor

Commits on Feb 27, 2018

  1. Update to ruby/mspec@d287466

    eregon committed Feb 27, 2018
    Copy the full SHA
    54eebf8 View commit details
  2. Update to ruby/spec@cbe855c

    eregon committed Feb 27, 2018
    Copy the full SHA
    debc0d1 View commit details
Showing with 458 additions and 312 deletions.
  1. +1 −1 spec/mspec/.travis.yml
  2. +18 −0 spec/mspec/tool/pull-latest-mspec-spec
  3. +1 −12 spec/mspec/tool/sync/sync-rubyspec.rb
  4. +2 −0 spec/ruby/CONTRIBUTING.md
  5. +3 −3 spec/ruby/README.md
  6. +25 −0 spec/ruby/command_line/dash_upper_e_spec.rb
  7. +1 −2 spec/ruby/core/array/clear_spec.rb
  8. +1 −1 spec/ruby/core/array/compact_spec.rb
  9. +16 −0 spec/ruby/core/array/filter_spec.rb
  10. +2 −2 spec/ruby/core/array/reject_spec.rb
  11. +2 −24 spec/ruby/core/array/select_spec.rb
  12. +2 −2 spec/ruby/core/array/shared/clone.rb
  13. +2 −2 spec/ruby/core/array/shared/collect.rb
  14. +32 −0 spec/ruby/core/array/shared/select.rb
  15. +24 −16 spec/ruby/core/encoding/converter/last_error_spec.rb
  16. +10 −21 spec/ruby/core/encoding/default_external_spec.rb
  17. +0 −17 spec/ruby/core/encoding/default_internal_spec.rb
  18. +9 −0 spec/ruby/core/enumerable/filter_spec.rb
  19. +1 −1 spec/ruby/core/env/shared/to_hash.rb
  20. +1 −1 spec/ruby/core/exception/no_method_error_spec.rb
  21. +1 −1 spec/ruby/core/file/shared/path.rb
  22. +1 −1 spec/ruby/core/hash/clone_spec.rb
  23. +1 −1 spec/ruby/core/hash/compare_by_identity_spec.rb
  24. +12 −0 spec/ruby/core/hash/filter_spec.rb
  25. +3 −76 spec/ruby/core/hash/select_spec.rb
  26. +91 −0 spec/ruby/core/hash/shared/select.rb
  27. +2 −2 spec/ruby/core/io/read_spec.rb
  28. +1 −1 spec/ruby/core/kernel/Float_spec.rb
  29. +25 −7 spec/ruby/core/kernel/Integer_spec.rb
  30. +6 −0 spec/ruby/core/matchdata/inspect_spec.rb
  31. +4 −4 spec/ruby/core/proc/block_pass_spec.rb
  32. +1 −2 spec/ruby/core/process/groups_spec.rb
  33. +2 −2 spec/ruby/core/process/times_spec.rb
  34. +2 −2 spec/ruby/core/{struct → process}/tms/cstime_spec.rb
  35. +2 −2 spec/ruby/core/{struct → process}/tms/cutime_spec.rb
  36. +1 −1 spec/ruby/core/{struct → process}/tms/element_reference_spec.rb
  37. +1 −1 spec/ruby/core/{struct → process}/tms/members_spec.rb
  38. +1 −1 spec/ruby/core/{struct → process}/tms/new_spec.rb
  39. +2 −2 spec/ruby/core/{struct → process}/tms/stime_spec.rb
  40. +2 −2 spec/ruby/core/{struct → process}/tms/utime_spec.rb
  41. +1 −1 spec/ruby/core/string/chr_spec.rb
  42. +1 −1 spec/ruby/core/string/clear_spec.rb
  43. +2 −3 spec/ruby/core/string/freeze_spec.rb
  44. +1 −1 spec/ruby/core/time/at_spec.rb
  45. +1 −1 spec/ruby/core/time/succ_spec.rb
  46. +2 −2 spec/ruby/language/defined_spec.rb
  47. +3 −3 spec/ruby/language/predefined_spec.rb
  48. +1 −1 spec/ruby/library/csv/generate_spec.rb
  49. +2 −1 spec/ruby/library/erb/defmethod/def_erb_method_spec.rb
  50. +9 −0 spec/ruby/library/erb/fixtures/classes.rb
  51. +19 −13 spec/ruby/library/erb/new_spec.rb
  52. +8 −0 spec/ruby/library/set/filter_spec.rb
  53. +2 −38 spec/ruby/library/set/select_spec.rb
  54. +42 −0 spec/ruby/library/set/shared/select.rb
  55. +9 −0 spec/ruby/library/set/sortedset/filter_spec.rb
  56. +2 −30 spec/ruby/library/set/sortedset/select_spec.rb
  57. +35 −0 spec/ruby/library/set/sortedset/shared/select.rb
  58. +2 −2 spec/ruby/optional/capi/gc_spec.rb
  59. +2 −2 spec/ruby/optional/capi/string_spec.rb
2 changes: 1 addition & 1 deletion spec/mspec/.travis.yml
Original file line number Diff line number Diff line change
@@ -20,6 +20,6 @@ matrix:
- gem update --system
- jdk: oraclejdk8
install:
- curl -L https://github.com/graalvm/truffleruby/releases/download/vm-enterprise-0.28/truffleruby-testing-0.28.tar.gz | tar xz
- curl -L https://github.com/oracle/truffleruby/releases/download/vm-enterprise-0.28/truffleruby-testing-0.28.tar.gz | tar xz
- source truffleruby/setup_env
- bundle install
18 changes: 18 additions & 0 deletions spec/mspec/tool/pull-latest-mspec-spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

# Assumes all commits have been synchronized to https://github.com/ruby/spec
# See spec/mspec/tool/sync/sync-rubyspec.rb

rm -rf spec/mspec
git clone --depth 1 https://github.com/ruby/mspec.git spec/mspec
commit=$(git -C spec/mspec log -n 1 --format='%h')
rm -rf spec/mspec/.git
git add spec/mspec
git commit -m "Update to ruby/mspec@${commit}"

rm -rf spec/ruby
git clone --depth 1 https://github.com/ruby/spec.git spec/ruby
commit=$(git -C spec/ruby log -n 1 --format='%h')
rm -rf spec/ruby/.git
git add spec/ruby
git commit -m "Update to ruby/spec@${commit}"
13 changes: 1 addition & 12 deletions spec/mspec/tool/sync/sync-rubyspec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
IMPLS = {
truffleruby: {
git: "https://github.com/graalvm/truffleruby.git",
git: "https://github.com/oracle/truffleruby.git",
from_commit: "f10ab6988d",
},
jruby: {
@@ -182,17 +182,6 @@ def test_new_specs
def verify_commits(impl)
puts
Dir.chdir(SOURCE_REPO) do
history = `git log master...`
history.lines.slice_before(/^commit \h{40}$/).each do |commit, *message|
commit = commit.chomp.split.last
message = message.join
if /\W(#\d+)/ === message
puts "Commit #{commit} contains an unqualified issue number: #{$1}"
puts "Replace it with #{impl.repo_org}/#{impl.repo_name}#{$1}"
sh "git", "rebase", "-i", "#{commit}^"
end
end

puts "Manually check commit messages:"
print "Press enter >"
STDIN.gets
2 changes: 2 additions & 0 deletions spec/ruby/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -158,6 +158,8 @@ guard -> { max_uint <= fixnum_max } do
end
```

Custom guards are better than a simple `if` as they allow [mspec commands](https://github.com/ruby/mspec/issues/30#issuecomment-312487779) to work properly.

In general, the usage of guards should be minimized as possible.

There are no guards to define implementation-specific behavior because
6 changes: 3 additions & 3 deletions spec/ruby/README.md
Original file line number Diff line number Diff line change
@@ -24,9 +24,9 @@ The language specs are grouped by keyword while the core and standard library sp

ruby/spec is known to be tested in these implementations for every commit:
* [MRI](http://rubyci.org/) on 30 platforms and 4 versions
* [JRuby](https://github.com/jruby/jruby/tree/master/spec/ruby) on Travis for both 1.7 and 9.x
* [TruffleRuby](https://github.com/graalvm/truffleruby) on Travis
* [Opal](https://github.com/opal/opal/tree/master/spec) on Travis
* [JRuby](https://github.com/jruby/jruby/tree/master/spec/ruby) for both 1.7 and 9.x
* [TruffleRuby](https://github.com/oracle/truffleruby)
* [Opal](https://github.com/opal/opal/tree/master/spec)

ruby/spec describes the behavior of Ruby 2.2 and more recent Ruby versions.
More precisely, every latest stable MRI release [passes](https://rubyci.org/) all specs of ruby/spec
25 changes: 25 additions & 0 deletions spec/ruby/command_line/dash_upper_e_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
describe "ruby -E" do
it "sets the external encoding with '-E external'" do
result = ruby_exe("print Encoding.default_external", options: '-E euc-jp')
result.should == "EUC-JP"
end

it "also sets the filesystem encoding with '-E external'" do
result = ruby_exe("print Encoding.find('filesystem')", options: '-E euc-jp')
result.should == "EUC-JP"
end

it "sets the external encoding with '-E external:'" do
result = ruby_exe("print Encoding.default_external", options: '-E Shift_JIS:')
result.should == "Shift_JIS"
end

it "sets the internal encoding with '-E :internal'" do
ruby_exe("print Encoding.default_internal", options: '-E :SHIFT_JIS').
should == 'Shift_JIS'
end

it "sets the external and internal encodings with '-E external:internal'" do
ruby_exe("puts Encoding.default_external, Encoding.default_internal", options: '-E euc-jp:SHIFT_JIS').
should == "EUC-JP\nShift_JIS\n"
end

it "raises a RuntimeError if used with -U" do
ruby_exe("p 1",
options: '-Eascii:ascii -U',
3 changes: 1 addition & 2 deletions spec/ruby/core/array/clear_spec.rb
Original file line number Diff line number Diff line change
@@ -10,8 +10,7 @@

it "returns self" do
a = [1]
oid = a.object_id
a.clear.object_id.should == oid
a.should equal a.clear
end

it "leaves the Array empty" do
2 changes: 1 addition & 1 deletion spec/ruby/core/array/compact_spec.rb
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@

it "returns self if some nil elements are removed" do
a = ['a', nil, 'b', false, 'c']
a.compact!.object_id.should == a.object_id
a.compact!.should equal a
end

it "returns nil if there are no nil elements to remove" do
16 changes: 16 additions & 0 deletions spec/ruby/core/array/filter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/select', __FILE__)

ruby_version_is "2.6" do
describe "Array#filter" do
it_behaves_like :array_select, :filter
end

describe "Array#filter!" do
it "returns nil if no changes were made in the array" do
[1, 2, 3].filter! { true }.should be_nil
end

it_behaves_like :keep_if, :filter!
end
end
4 changes: 2 additions & 2 deletions spec/ruby/core/array/reject_spec.rb
Original file line number Diff line number Diff line change
@@ -9,9 +9,9 @@
ary = [1, 2, 3, 4, 5]
ary.reject { true }.should == []
ary.reject { false }.should == ary
ary.reject { false }.object_id.should_not == ary.object_id
ary.reject { false }.should_not equal ary
ary.reject { nil }.should == ary
ary.reject { nil }.object_id.should_not == ary.object_id
ary.reject { nil }.should_not equal ary
ary.reject { 5 }.should == []
ary.reject { |i| i < 3 }.should == [3, 4, 5]
ary.reject { |i| i % 2 == 0 }.should == [1, 3, 5]
26 changes: 2 additions & 24 deletions spec/ruby/core/array/select_spec.rb
Original file line number Diff line number Diff line change
@@ -1,30 +1,8 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/enumeratorize', __FILE__)
require File.expand_path('../shared/keep_if', __FILE__)
require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)
require File.expand_path('../shared/select', __FILE__)

describe "Array#select" do
it_behaves_like :enumeratorize, :select
it_behaves_like :enumeratorized_with_origin_size, :select, [1,2,3]

it "returns a new array of elements for which block is true" do
[1, 3, 4, 5, 6, 9].select { |i| i % ((i + 1) / 2) == 0}.should == [1, 4, 6]
end

it "does not return subclass instance on Array subclasses" do
ArraySpecs::MyArray[1, 2, 3].select { true }.should be_an_instance_of(Array)
end

it "properly handles recursive arrays" do
empty = ArraySpecs.empty_recursive_array
empty.select { true }.should == empty
empty.select { false }.should == []

array = ArraySpecs.recursive_array
array.select { true }.should == [1, 'two', 3.0, array, array, array, array, array]
array.select { false }.should == []
end
it_behaves_like :array_select, :select
end

describe "Array#select!" do
4 changes: 2 additions & 2 deletions spec/ruby/core/array/shared/clone.rb
Original file line number Diff line number Diff line change
@@ -7,8 +7,8 @@
it "produces a shallow copy where the references are directly copied" do
a = [mock('1'), mock('2')]
b = a.send @method
b.first.object_id.should == a.first.object_id
b.last.object_id.should == a.last.object_id
b.first.should equal a.first
b.last.should equal a.last
end

it "creates a new array containing all elements or the original" do
4 changes: 2 additions & 2 deletions spec/ruby/core/array/shared/collect.rb
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
a = ['a', 'b', 'c', 'd']
b = a.send(@method) { |i| i + '!' }
b.should == ["a!", "b!", "c!", "d!"]
b.object_id.should_not == a.object_id
b.should_not equal a
end

it "does not return subclass instance" do
@@ -70,7 +70,7 @@
it "returns self" do
a = [1, 2, 3, 4, 5]
b = a.send(@method) {|i| i+1 }
a.object_id.should == b.object_id
a.should equal b
end

it "returns the evaluated value of block but its contents is partially modified, if it broke in the block" do
32 changes: 32 additions & 0 deletions spec/ruby/core/array/shared/select.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/classes', __FILE__)
require File.expand_path('../../shared/enumeratorize', __FILE__)
require File.expand_path('../../shared/keep_if', __FILE__)
require File.expand_path('../../../enumerable/shared/enumeratorized', __FILE__)

describe :array_select, shared: true do
it_should_behave_like :enumeratorize

before :each do
@object = [1,2,3]
end
it_should_behave_like :enumeratorized_with_origin_size

it "returns a new array of elements for which block is true" do
[1, 3, 4, 5, 6, 9].send(@method) { |i| i % ((i + 1) / 2) == 0}.should == [1, 4, 6]
end

it "does not return subclass instance on Array subclasses" do
ArraySpecs::MyArray[1, 2, 3].send(@method) { true }.should be_an_instance_of(Array)
end

it "properly handles recursive arrays" do
empty = ArraySpecs.empty_recursive_array
empty.send(@method) { true }.should == empty
empty.send(@method) { false }.should == []

array = ArraySpecs.recursive_array
array.send(@method) { true }.should == [1, 'two', 3.0, array, array, array, array, array]
array.send(@method) { false }.should == []
end
end
40 changes: 24 additions & 16 deletions spec/ruby/core/encoding/converter/last_error_spec.rb
Original file line number Diff line number Diff line change
@@ -55,31 +55,39 @@
it "returns an Encoding::InvalidByteSequenceError when the last call to #convert produced one" do
ec = Encoding::Converter.new("utf-8", "iso-8859-1")
exception = nil
lambda do
begin
ec.convert("\xf1abcd")
rescue Encoding::InvalidByteSequenceError => e
exception = e
raise e
end
end.should raise_error(Encoding::InvalidByteSequenceError)
-> {
ec.convert("\xf1abcd")
}.should raise_error(Encoding::InvalidByteSequenceError) { |e|
exception = e
}
ec.last_error.should be_an_instance_of(Encoding::InvalidByteSequenceError)
ec.last_error.message.should == exception.message
end

it "returns an Encoding::UndefinedConversionError when the last call to #convert produced one" do
ec = Encoding::Converter.new("utf-8", "iso-8859-1")
exception = nil
lambda do
begin
ec.convert("\u{9899}")
rescue Encoding::UndefinedConversionError => e
exception = e
raise e
end
end.should raise_error(Encoding::UndefinedConversionError)
-> {
ec.convert("\u{9899}")
}.should raise_error(Encoding::UndefinedConversionError) { |e|
exception = e
}
ec.last_error.should be_an_instance_of(Encoding::UndefinedConversionError)
ec.last_error.message.should == exception.message
ec.last_error.message.should include "from UTF-8 to ISO-8859-1"
end

it "returns the last error of #convert with a message showing the transcoding path" do
ec = Encoding::Converter.new("iso-8859-1", "Big5")
exception = nil
-> {
ec.convert("\xE9") # é in ISO-8859-1
}.should raise_error(Encoding::UndefinedConversionError) { |e|
exception = e
}
ec.last_error.should be_an_instance_of(Encoding::UndefinedConversionError)
ec.last_error.message.should == exception.message
ec.last_error.message.should include "from ISO-8859-1 to UTF-8 to Big5"
end
end
end
31 changes: 10 additions & 21 deletions spec/ruby/core/encoding/default_external_spec.rb
Original file line number Diff line number Diff line change
@@ -15,25 +15,8 @@
end

it "returns the default external encoding" do
Encoding.default_external = Encoding::UTF_8
Encoding.default_external.should == Encoding::UTF_8
end

describe "with command line options" do
it "is not changed by the -U option" do
result = ruby_exe("print Encoding.default_external", options: '-U')
result.should == Encoding.default_external.name
end

it "returns the encoding specified by '-E external'" do
result = ruby_exe("print Encoding.default_external", options: '-E euc-jp')
result.should == "EUC-JP"
end

it "returns the encoding specified by '-E external:'" do
result = ruby_exe("print Encoding.default_external", options: '-E Shift_JIS:')
result.should == "Shift_JIS"
end
Encoding.default_external = Encoding::SHIFT_JIS
Encoding.default_external.should == Encoding::SHIFT_JIS
end
end

@@ -47,8 +30,14 @@
end

it "sets the default external encoding" do
Encoding.default_external = Encoding::UTF_8
Encoding.default_external.should == Encoding::UTF_8
Encoding.default_external = Encoding::SHIFT_JIS
Encoding.default_external.should == Encoding::SHIFT_JIS
Encoding.find('external').should == Encoding::SHIFT_JIS
end

it "also sets the filesystem encoding" do
Encoding.default_external = Encoding::SHIFT_JIS
Encoding.find('filesystem').should == Encoding::SHIFT_JIS
end

it "can accept a name of an encoding as a String" do
17 changes: 0 additions & 17 deletions spec/ruby/core/encoding/default_internal_spec.rb
Original file line number Diff line number Diff line change
@@ -28,23 +28,6 @@
Encoding.default_internal = Encoding::ASCII_8BIT
Encoding.default_internal.should == Encoding::ASCII_8BIT
end

describe "with command line options" do
it "returns Encoding::UTF_8 if ruby was invoked with -U" do
ruby_exe("print Encoding.default_internal", options: '-U').
should == 'UTF-8'
end

it "uses the encoding specified when ruby is invoked with an '-E :internal' argument" do
ruby_exe("print Encoding.default_internal", options: '-E :SHIFT_JIS').
should == 'Shift_JIS'
end

it "uses the encoding specified when ruby is invoked with an '-E external:internal' argument" do
ruby_exe("print Encoding.default_internal", options: '-E UTF-8:SHIFT_JIS').
should == 'Shift_JIS'
end
end
end

describe "Encoding.default_internal=" do
9 changes: 9 additions & 0 deletions spec/ruby/core/enumerable/filter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/find_all', __FILE__)

ruby_version_is "2.6" do
describe "Enumerable#filter" do
it_behaves_like(:enumerable_find_all , :filter)
end
end
2 changes: 1 addition & 1 deletion spec/ruby/core/env/shared/to_hash.rb
Original file line number Diff line number Diff line change
@@ -17,6 +17,6 @@

it "duplicates the ENV when converting to a Hash" do
h = ENV.send(@method)
h.object_id.should_not == ENV.object_id
h.should_not equal ENV
end
end
2 changes: 1 addition & 1 deletion spec/ruby/core/exception/no_method_error_spec.rb
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@
NoMethodErrorSpecs::NoMethodErrorB.new.foo(1,a)
rescue Exception => e
e.args.should == [1,a]
e.args[1].object_id.should == a.object_id
e.args[1].should equal a
end
end
end
2 changes: 1 addition & 1 deletion spec/ruby/core/file/shared/path.rb
Original file line number Diff line number Diff line change
@@ -69,7 +69,7 @@
File.open(@dir, File::RDWR | File::TMPFILE) do |f|
-> { f.send(@method) }.should raise_error(IOError)
end
rescue Errno::EOPNOTSUPP
rescue Errno::EOPNOTSUPP, Errno::EINVAL
# EOPNOTSUPP: no support from the filesystem
1.should == 1
end
2 changes: 1 addition & 1 deletion spec/ruby/core/hash/clone_spec.rb
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
clone = hash.clone

clone.should == hash
clone.object_id.should_not == hash.object_id
clone.should_not equal hash
end
end

2 changes: 1 addition & 1 deletion spec/ruby/core/hash/compare_by_identity_spec.rb
Original file line number Diff line number Diff line change
@@ -105,7 +105,7 @@ def o.hash; 123; end
@idh[foo] = true
@idh[foo] = true
@idh.size.should == 1
@idh.keys.first.object_id.should == foo.object_id
@idh.keys.first.should equal foo
end

ruby_bug "#12855", "2.2.0"..."2.4.1" do
12 changes: 12 additions & 0 deletions spec/ruby/core/hash/filter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/select', __FILE__)

ruby_version_is "2.6" do
describe "Hash#filter" do
it_behaves_like :hash_select, :filter
end

describe "Hash#filter!" do
it_behaves_like :hash_select!, :filter!
end
end
79 changes: 3 additions & 76 deletions spec/ruby/core/hash/select_spec.rb
Original file line number Diff line number Diff line change
@@ -1,83 +1,10 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/iteration', __FILE__)
require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)
require File.expand_path('../shared/select', __FILE__)

describe "Hash#select" do
before :each do
@hsh = { 1 => 2, 3 => 4, 5 => 6 }
@empty = {}
end

it "yields two arguments: key and value" do
all_args = []
{ 1 => 2, 3 => 4 }.select { |*args| all_args << args }
all_args.sort.should == [[1, 2], [3, 4]]
end

it "returns a Hash of entries for which block is true" do
a_pairs = { 'a' => 9, 'c' => 4, 'b' => 5, 'd' => 2 }.select { |k,v| v % 2 == 0 }
a_pairs.should be_an_instance_of(Hash)
a_pairs.sort.should == [['c', 4], ['d', 2]]
end

it "processes entries with the same order as reject" do
h = { a: 9, c: 4, b: 5, d: 2 }

select_pairs = []
reject_pairs = []
h.dup.select { |*pair| select_pairs << pair }
h.reject { |*pair| reject_pairs << pair }

select_pairs.should == reject_pairs
end

it "returns an Enumerator when called on a non-empty hash without a block" do
@hsh.select.should be_an_instance_of(Enumerator)
end

it "returns an Enumerator when called on an empty hash without a block" do
@empty.select.should be_an_instance_of(Enumerator)
end

it_behaves_like :hash_iteration_no_block, :select
it_behaves_like :enumeratorized_with_origin_size, :select, { 1 => 2, 3 => 4, 5 => 6 }
it_behaves_like :hash_select, :select
end

describe "Hash#select!" do
before :each do
@hsh = { 1 => 2, 3 => 4, 5 => 6 }
@empty = {}
end

it "is equivalent to keep_if if changes are made" do
h = { a: 2 }
h.select! { |k,v| v <= 1 }.should equal h

h = { 1 => 2, 3 => 4 }
all_args_select = []
h.dup.select! { |*args| all_args_select << args }
all_args_select.should == [[1, 2], [3, 4]]
end

it "removes all entries if the block is false" do
h = { a: 1, b: 2, c: 3 }
h.select! { |k,v| false }.should equal(h)
h.should == {}
end

it "returns nil if no changes were made" do
{ a: 1 }.select! { |k,v| v <= 1 }.should == nil
end

it "raises a #{frozen_error_class} if called on an empty frozen instance" do
lambda { HashSpecs.empty_frozen_hash.select! { false } }.should raise_error(frozen_error_class)
end

it "raises a #{frozen_error_class} if called on a frozen instance that would not be modified" do
lambda { HashSpecs.frozen_hash.select! { true } }.should raise_error(frozen_error_class)
end

it_behaves_like :hash_iteration_no_block, :select!
it_behaves_like :enumeratorized_with_origin_size, :select!, { 1 => 2, 3 => 4, 5 => 6 }
it_behaves_like :hash_select!, :select!
end
91 changes: 91 additions & 0 deletions spec/ruby/core/hash/shared/select.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/classes', __FILE__)
require File.expand_path('../../shared/iteration', __FILE__)
require File.expand_path('../../../enumerable/shared/enumeratorized', __FILE__)

describe :hash_select, shared: true do
before :each do
@hsh = { 1 => 2, 3 => 4, 5 => 6 }
@empty = {}
end

it "yields two arguments: key and value" do
all_args = []
{ 1 => 2, 3 => 4 }.send(@method) { |*args| all_args << args }
all_args.sort.should == [[1, 2], [3, 4]]
end

it "returns a Hash of entries for which block is true" do
a_pairs = { 'a' => 9, 'c' => 4, 'b' => 5, 'd' => 2 }.send(@method) { |k,v| v % 2 == 0 }
a_pairs.should be_an_instance_of(Hash)
a_pairs.sort.should == [['c', 4], ['d', 2]]
end

it "processes entries with the same order as reject" do
h = { a: 9, c: 4, b: 5, d: 2 }

select_pairs = []
reject_pairs = []
h.dup.send(@method) { |*pair| select_pairs << pair }
h.reject { |*pair| reject_pairs << pair }

select_pairs.should == reject_pairs
end

it "returns an Enumerator when called on a non-empty hash without a block" do
@hsh.send(@method).should be_an_instance_of(Enumerator)
end

it "returns an Enumerator when called on an empty hash without a block" do
@empty.send(@method).should be_an_instance_of(Enumerator)
end

it_should_behave_like :hash_iteration_no_block

before :each do
@object = { 1 => 2, 3 => 4, 5 => 6 }
end
it_should_behave_like :enumeratorized_with_origin_size
end

describe :hash_select!, shared: true do
before :each do
@hsh = { 1 => 2, 3 => 4, 5 => 6 }
@empty = {}
end

it "is equivalent to keep_if if changes are made" do
h = { a: 2 }
h.send(@method) { |k,v| v <= 1 }.should equal h

h = { 1 => 2, 3 => 4 }
all_args_select = []
h.dup.send(@method) { |*args| all_args_select << args }
all_args_select.should == [[1, 2], [3, 4]]
end

it "removes all entries if the block is false" do
h = { a: 1, b: 2, c: 3 }
h.send(@method) { |k,v| false }.should equal(h)
h.should == {}
end

it "returns nil if no changes were made" do
{ a: 1 }.send(@method) { |k,v| v <= 1 }.should == nil
end

it "raises a #{frozen_error_class} if called on an empty frozen instance" do
lambda { HashSpecs.empty_frozen_hash.send(@method) { false } }.should raise_error(frozen_error_class)
end

it "raises a #{frozen_error_class} if called on a frozen instance that would not be modified" do
lambda { HashSpecs.frozen_hash.send(@method) { true } }.should raise_error(frozen_error_class)
end

it_should_behave_like :hash_iteration_no_block

before :each do
@object = { 1 => 2, 3 => 4, 5 => 6 }
end
it_should_behave_like :enumeratorized_with_origin_size
end
4 changes: 2 additions & 2 deletions spec/ruby/core/io/read_spec.rb
Original file line number Diff line number Diff line change
@@ -257,15 +257,15 @@
it "returns the given buffer" do
buf = ""

@io.read(nil, buf).object_id.should == buf.object_id
@io.read(nil, buf).should equal buf
end

it "coerces the second argument to string and uses it as a buffer" do
buf = "ABCDE"
obj = mock("buff")
obj.should_receive(:to_str).any_number_of_times.and_return(buf)

@io.read(15, obj).object_id.should_not == obj.object_id
@io.read(15, obj).should_not equal obj
buf.should == @contents
end

2 changes: 1 addition & 1 deletion spec/ruby/core/kernel/Float_spec.rb
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
float = 1.12
float2 = @object.send(:Float, float)
float2.should == float
float2.object_id.should == float.object_id
float2.should equal float
end

it "returns a Float for Fixnums" do
32 changes: 25 additions & 7 deletions spec/ruby/core/kernel/Integer_spec.rb
Original file line number Diff line number Diff line change
@@ -10,11 +10,29 @@
Integer(100).should == 100
end

it "uncritically return the value of to_int even if it is not an Integer" do
obj = mock("object")
obj.should_receive(:to_int).and_return("1")
obj.should_not_receive(:to_i)
Integer(obj).should == "1"
ruby_version_is ""..."2.6" do
it "uncritically return the value of to_int even if it is not an Integer" do
obj = mock("object")
obj.should_receive(:to_int).and_return("1")
obj.should_not_receive(:to_i)
Integer(obj).should == "1"
end
end

ruby_version_is "2.6" do
it "raises a TypeError when to_int returns not-an-Integer object and to_i returns nil" do
obj = mock("object")
obj.should_receive(:to_int).and_return("1")
obj.should_receive(:to_i).and_return(nil)
lambda { Integer(obj) }.should raise_error(TypeError)
end

it "return a result of to_i when to_int does not return an Integer" do
obj = mock("object")
obj.should_receive(:to_int).and_return("1")
obj.should_receive(:to_i).and_return(42)
Integer(obj).should == 42
end
end

it "raises a TypeError when passed nil" do
@@ -45,9 +63,9 @@

it "returns the value of to_int if the result is a Bignum" do
obj = mock("object")
obj.should_receive(:to_int).and_return(2e100)
obj.should_receive(:to_int).and_return(2 * 10**100)
obj.should_not_receive(:to_i)
Integer(obj).should == 2e100
Integer(obj).should == 2 * 10**100
end

it "calls to_i on an object whose to_int returns nil" do
6 changes: 6 additions & 0 deletions spec/ruby/core/matchdata/inspect_spec.rb
Original file line number Diff line number Diff line change
@@ -14,4 +14,10 @@
# it makes perfect sense. See JRUBY-4558 for example.
@match_data.inspect.should == '#<MatchData "HX1138" 1:"H" 2:"X" 3:"113" 4:"8">'
end

it "returns a human readable representation of named captures" do
match_data = "abc def ghi".match(/(?<first>\w+)\s+(?<last>\w+)\s+(\w+)/)

match_data.inspect.should == '#<MatchData "abc def ghi" first:"abc" last:"def">'
end
end
8 changes: 4 additions & 4 deletions spec/ruby/core/proc/block_pass_spec.rb
Original file line number Diff line number Diff line change
@@ -8,14 +8,14 @@ def revivify(&b)
it "remains the same object if re-vivified by the target method" do
p = Proc.new {}
p2 = revivify(&p)
p.object_id.should == p2.object_id
p.should equal p2
p.should == p2
end

it "remains the same object if reconstructed with Proc.new" do
p = Proc.new {}
p2 = Proc.new(&p)
p.object_id.should == p2.object_id
p.should equal p2
p.should == p2
end
end
@@ -28,14 +28,14 @@ def revivify
it "remains the same object if re-vivified by the target method" do
p = Proc.new {}
p2 = revivify(&p)
p.object_id.should == p2.object_id
p.should equal p2
p.should == p2
end

it "remains the same object if reconstructed with Proc.new" do
p = Proc.new {}
p2 = Proc.new(&p)
p.object_id.should == p2.object_id
p.should equal p2
p.should == p2
end
end
3 changes: 1 addition & 2 deletions spec/ruby/core/process/groups_spec.rb
Original file line number Diff line number Diff line change
@@ -53,9 +53,8 @@

platform_is_not :aix do
it "raises Errno::EPERM" do
groups = Process.groups
lambda {
Process.groups = groups
Process.groups = [0]
}.should raise_error(Errno::EPERM)
end
end
4 changes: 2 additions & 2 deletions spec/ruby/core/process/times_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require File.expand_path('../../../spec_helper', __FILE__)

describe "Process.times" do
it "returns a Struct::Tms" do
Process.times.should be_kind_of(Struct::Tms)
it "returns a Process::Tms" do
Process.times.should be_kind_of(Process::Tms)
end

it "returns current cpu times" do
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require File.expand_path('../../../../spec_helper', __FILE__)

describe "Struct::Tms#cstime" do
describe "Process::Tms#cstime" do
it "needs to be reviewed for spec completeness"
end

describe "Struct::Tms#cstime=" do
describe "Process::Tms#cstime=" do
it "needs to be reviewed for spec completeness"
end
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require File.expand_path('../../../../spec_helper', __FILE__)

describe "Struct::Tms#cutime" do
describe "Process::Tms#cutime" do
it "needs to be reviewed for spec completeness"
end

describe "Struct::Tms#cutime=" do
describe "Process::Tms#cutime=" do
it "needs to be reviewed for spec completeness"
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require File.expand_path('../../../../spec_helper', __FILE__)

describe "Struct::Tms.[]" do
describe "Process::Tms.[]" do
it "needs to be reviewed for spec completeness"
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require File.expand_path('../../../../spec_helper', __FILE__)

describe "Struct::Tms.members" do
describe "Process::Tms.members" do
it "needs to be reviewed for spec completeness"
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require File.expand_path('../../../../spec_helper', __FILE__)

describe "Struct::Tms.new" do
describe "Process::Tms.new" do
it "needs to be reviewed for spec completeness"
end
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require File.expand_path('../../../../spec_helper', __FILE__)

describe "Struct::Tms#stime" do
describe "Process::Tms#stime" do
it "needs to be reviewed for spec completeness"
end

describe "Struct::Tms#stime=" do
describe "Process::Tms#stime=" do
it "needs to be reviewed for spec completeness"
end
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require File.expand_path('../../../../spec_helper', __FILE__)

describe "Struct::Tms#utime" do
describe "Process::Tms#utime" do
it "needs to be reviewed for spec completeness"
end

describe "Struct::Tms#utime=" do
describe "Process::Tms#utime=" do
it "needs to be reviewed for spec completeness"
end
2 changes: 1 addition & 1 deletion spec/ruby/core/string/chr_spec.rb
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
describe "String#chr" do
it "returns a copy of self" do
s = 'e'
s.object_id.should_not == s.chr.object_id
s.should_not equal s.chr
end

it "returns a String" do
2 changes: 1 addition & 1 deletion spec/ruby/core/string/clear_spec.rb
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
it "returns self after emptying it" do
cleared = @s.clear
cleared.should == ""
cleared.object_id.should == @s.object_id
cleared.should equal @s
end

it "preserves its encoding" do
5 changes: 2 additions & 3 deletions spec/ruby/core/string/freeze_spec.rb
Original file line number Diff line number Diff line change
@@ -3,12 +3,11 @@
describe "String#freeze" do

it "produces the same object whenever called on an instance of a literal in the source" do
ids = Array.new(2) { "abc".freeze.object_id }
ids.first.should == ids.last
"abc".freeze.should equal "abc".freeze
end

it "doesn't produce the same object for different instances of literals in the source" do
"abc".object_id.should_not == "abc".object_id
"abc".should_not equal "abc"
end

it "being a special form doesn't change the value of defined?" do
2 changes: 1 addition & 1 deletion spec/ruby/core/time/at_spec.rb
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@
it "creates a dup time object with the value given by time" do
t1 = Time.new
t2 = Time.at(t1)
t1.object_id.should_not == t2.object_id
t1.should_not equal t2
end

it "returns a UTC time if the argument is UTC" do
2 changes: 1 addition & 1 deletion spec/ruby/core/time/succ_spec.rb
Original file line number Diff line number Diff line change
@@ -14,6 +14,6 @@
-> {
t2 = t1.succ
}.should complain(/Time#succ is obsolete/)
t1.object_id.should_not == t2.object_id
t1.should_not equal t2
end
end
4 changes: 2 additions & 2 deletions spec/ruby/language/defined_spec.rb
Original file line number Diff line number Diff line change
@@ -756,13 +756,13 @@
defined?(DefinedSpecs::String).should be_nil
end

ruby_version_is ""..."2.6" do
ruby_version_is ""..."2.5" do
it "returns 'constant' when a constant is defined on top-level but not on the class" do
defined?(DefinedSpecs::Basic::String).should == 'constant'
end
end

ruby_version_is "2.6" do
ruby_version_is "2.5" do
it "returns nil when a constant is defined on top-level but not on the class" do
defined?(DefinedSpecs::Basic::String).should be_nil
end
6 changes: 3 additions & 3 deletions spec/ruby/language/predefined_spec.rb
Original file line number Diff line number Diff line change
@@ -44,11 +44,11 @@
it "is set to contain the MatchData object of the last match if successful" do
md = /foo/.match 'foo'
$~.should be_kind_of(MatchData)
$~.object_id.should == md.object_id
$~.should equal md

/bar/ =~ 'bar'
$~.should be_kind_of(MatchData)
$~.object_id.should_not == md.object_id
$~.should_not equal md
end

it "is set to nil if the last match was unsuccessful" do
@@ -828,7 +828,7 @@ def obj.foo2; yield; end

describe "Global variable $\"" do
it "is an alias for $LOADED_FEATURES" do
$".object_id.should == $LOADED_FEATURES.object_id
$".should equal $LOADED_FEATURES
end

it "is read-only" do
2 changes: 1 addition & 1 deletion spec/ruby/library/csv/generate_spec.rb
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@
csv.add_row [1, 2, 3]
csv << [4, 5, 6]
end
csv_str.object_id.should == str.object_id
csv_str.should equal str
str.should == "1,2,3\n4,5,6\n"
end
end
3 changes: 2 additions & 1 deletion spec/ruby/library/erb/defmethod/def_erb_method_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'erb'
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/classes', __FILE__)

describe "ERB::DefMethod.def_erb_method" do

@@ -50,7 +51,7 @@ def initialize(items)
MY_INPUT4_FOR_ERB = input
class MyClass4ForErb
extend ERB::DefMethod
erb = ERB.new(MY_INPUT4_FOR_ERB, nil, '<>')
erb = ERBSpecs.new_erb(MY_INPUT4_FOR_ERB, trim_mode: '<>')
def_erb_method('render()', erb)
def initialize(items)
@items = items
9 changes: 9 additions & 0 deletions spec/ruby/library/erb/fixtures/classes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module ERBSpecs
def self.new_erb(input, trim_mode: nil)
if ruby_version_is "2.6"
ERB.new(input, trim_mode: trim_mode)
else
ERB.new(input, nil, trim_mode)
end
end
end
32 changes: 19 additions & 13 deletions spec/ruby/library/erb/new_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'erb'
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)

describe "ERB.new" do
before :all do
@@ -31,21 +32,21 @@
it "compiles eRuby script into ruby code when trim mode is 0 or not specified" do
expected = "<ul>\n\n\n\n<li>1</li>\n\n\n\n<li>2</li>\n\n\n\n<li>3</li>\n\n\n</ul>\n"
[0, '', nil].each do |trim_mode|
ERB.new(@eruby_str, nil, trim_mode).result.should == expected
ERBSpecs.new_erb(@eruby_str, trim_mode: trim_mode).result.should == expected
end
end

it "removes '\n' when trim_mode is 1 or '>'" do
expected = "<ul>\n<li>1</li>\n<li>2</li>\n<li>3</li>\n</ul>\n"
[1, '>'].each do |trim_mode|
ERB.new(@eruby_str, nil, trim_mode).result.should == expected
ERBSpecs.new_erb(@eruby_str, trim_mode: trim_mode).result.should == expected
end
end

it "removes spaces at beginning of line and '\n' when trim_mode is 2 or '<>'" do
expected = "<ul>\n<li>1</li>\n<li>2</li>\n<li>3</li>\n</ul>\n"
[2, '<>'].each do |trim_mode|
ERB.new(@eruby_str, nil, trim_mode).result.should == expected
ERBSpecs.new_erb(@eruby_str, trim_mode: trim_mode).result.should == expected
end
end

@@ -61,7 +62,7 @@
</ul>
END

ERB.new(input, nil, '-').result.should == expected
ERBSpecs.new_erb(input, trim_mode: '-').result.should == expected
end


@@ -75,23 +76,23 @@
END

lambda {
ERB.new(input, nil, '-').result
ERBSpecs.new_erb(input, trim_mode: '-').result
}.should raise_error(SyntaxError)
end

it "regards lines starting with '%' as '<% ... %>' when trim_mode is '%'" do
expected = "<ul>\n <li>1\n \n <li>2\n \n <li>3\n \n\n</ul>\n%%\n"
ERB.new(@eruby_str2, nil, "%").result.should == expected
ERBSpecs.new_erb(@eruby_str2, trim_mode: "%").result.should == expected
end
it "regards lines starting with '%' as '<% ... %>' and remove \"\\n\" when trim_mode is '%>'" do
expected = "<ul>\n <li>1 <li>2 <li>3 </ul>\n%%\n"
ERB.new(@eruby_str2, nil, '%>').result.should == expected
ERBSpecs.new_erb(@eruby_str2, trim_mode: '%>').result.should == expected
end


it "regard lines starting with '%' as '<% ... %>' and remove \"\\n\" when trim_mode is '%<>'" do
expected = "<ul>\n <li>1\n \n <li>2\n \n <li>3\n \n</ul>\n%%\n"
ERB.new(@eruby_str2, nil, '%<>').result.should == expected
ERBSpecs.new_erb(@eruby_str2, trim_mode: '%<>').result.should == expected
end


@@ -106,13 +107,18 @@
%%%
END

ERB.new(input, nil, '%-').result.should == expected
ERBSpecs.new_erb(input, trim_mode: '%-').result.should == expected
end

it "changes '_erbout' variable name in the produced source" do
input = @eruby_str
match_erbout = ERB.new(input, nil, nil).src
match_buf = ERB.new(input, nil, nil, 'buf').src
if RUBY_VERSION >= '2.6'
match_erbout = ERB.new(input, trim_mode: nil).src
match_buf = ERB.new(input, trim_mode: nil, eoutvar: 'buf').src
else
match_erbout = ERB.new(input, nil, nil).src
match_buf = ERB.new(input, nil, nil, 'buf').src
end
match_erbout.gsub("_erbout", "buf").should == match_buf
end

@@ -123,8 +129,8 @@
<b><%#= item %></b>
<%# end %>
END
ERB.new(input).result.should == "\n<b></b>\n\n"
ERB.new(input, nil, '<>').result.should == "<b></b>\n"
ERBSpecs.new_erb(input).result.should == "\n<b></b>\n\n"
ERBSpecs.new_erb(input, trim_mode: '<>').result.should == "<b></b>\n"
end

it "forget local variables defined previous one" do
8 changes: 8 additions & 0 deletions spec/ruby/library/set/filter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/select', __FILE__)

ruby_version_is "2.6" do
describe "Set#filter!" do
it_behaves_like :set_select_bang, :filter!
end
end
40 changes: 2 additions & 38 deletions spec/ruby/library/set/select_spec.rb
Original file line number Diff line number Diff line change
@@ -1,42 +1,6 @@
require File.expand_path('../../../spec_helper', __FILE__)
require 'set'
require File.expand_path('../shared/select', __FILE__)

describe "Set#select!" do
before :each do
@set = Set["one", "two", "three"]
end

it "yields every element of self" do
ret = []
@set.select! { |x| ret << x }
ret.sort.should == ["one", "two", "three"].sort
end

it "keeps every element from self for which the passed block returns true" do
@set.select! { |x| x.size != 3 }
@set.size.should eql(1)

@set.should_not include("one")
@set.should_not include("two")
@set.should include("three")
end

it "returns self when self was modified" do
@set.select! { false }.should equal(@set)
end

it "returns nil when self was not modified" do
@set.select! { true }.should be_nil
end

it "returns an Enumerator when passed no block" do
enum = @set.select!
enum.should be_an_instance_of(Enumerator)

enum.each { |x| x.size != 3 }

@set.should_not include("one")
@set.should_not include("two")
@set.should include("three")
end
it_behaves_like :set_select_bang, :select!
end
42 changes: 42 additions & 0 deletions spec/ruby/library/set/shared/select.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require 'set'

describe :set_select_bang, shared: true do
before :each do
@set = Set["one", "two", "three"]
end

it "yields every element of self" do
ret = []
@set.send(@method) { |x| ret << x }
ret.sort.should == ["one", "two", "three"].sort
end

it "keeps every element from self for which the passed block returns true" do
@set.send(@method) { |x| x.size != 3 }
@set.size.should eql(1)

@set.should_not include("one")
@set.should_not include("two")
@set.should include("three")
end

it "returns self when self was modified" do
@set.send(@method) { false }.should equal(@set)
end

it "returns nil when self was not modified" do
@set.send(@method) { true }.should be_nil
end

it "returns an Enumerator when passed no block" do
enum = @set.send(@method)
enum.should be_an_instance_of(Enumerator)

enum.each { |x| x.size != 3 }

@set.should_not include("one")
@set.should_not include("two")
@set.should include("three")
end
end
9 changes: 9 additions & 0 deletions spec/ruby/library/set/sortedset/filter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../shared/select', __FILE__)
require 'set'

ruby_version_is "2.6" do
describe "SortedSet#filter!" do
it_behaves_like :sorted_set_select_bang, :filter!
end
end
32 changes: 2 additions & 30 deletions spec/ruby/library/set/sortedset/select_spec.rb
Original file line number Diff line number Diff line change
@@ -1,35 +1,7 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../shared/select', __FILE__)
require 'set'

describe "SortedSet#select!" do
before :each do
@set = SortedSet["one", "two", "three"]
end

it "yields each Object in self in sorted order" do
res = []
@set.select! { |x| res << x }
res.should == ["one", "two", "three"].sort
end

it "keeps every element from self for which the passed block returns true" do
@set.select! { |x| x.size != 3 }
@set.to_a.should == ["three"]
end

it "returns self when self was modified" do
@set.select! { false }.should equal(@set)
end

it "returns nil when self was not modified" do
@set.select! { true }.should be_nil
end

it "returns an Enumerator when passed no block" do
enum = @set.select!
enum.should be_an_instance_of(Enumerator)

enum.each { |x| x.size != 3 }
@set.to_a.should == ["three"]
end
it_behaves_like :sorted_set_select_bang, :select!
end
35 changes: 35 additions & 0 deletions spec/ruby/library/set/sortedset/shared/select.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'set'

describe :sorted_set_select_bang, shared: true do
before :each do
@set = SortedSet["one", "two", "three"]
end

it "yields each Object in self in sorted order" do
res = []
@set.send(@method) { |x| res << x }
res.should == ["one", "two", "three"].sort
end

it "keeps every element from self for which the passed block returns true" do
@set.send(@method) { |x| x.size != 3 }
@set.to_a.should == ["three"]
end

it "returns self when self was modified" do
@set.send(@method) { false }.should equal(@set)
end

it "returns nil when self was not modified" do
@set.send(@method) { true }.should be_nil
end

it "returns an Enumerator when passed no block" do
enum = @set.send(@method)
enum.should be_an_instance_of(Enumerator)

enum.each { |x| x.size != 3 }
@set.to_a.should == ["three"]
end
end
4 changes: 2 additions & 2 deletions spec/ruby/optional/capi/gc_spec.rb
Original file line number Diff line number Diff line change
@@ -9,9 +9,9 @@

it "correctly gets the value from a registered address" do
@f.registered_tagged_address.should == 10
@f.registered_tagged_address.object_id.should == @f.registered_tagged_address.object_id
@f.registered_tagged_address.should equal(@f.registered_tagged_address)
@f.registered_reference_address.should == "Globally registered data"
@f.registered_reference_address.object_id.should == @f.registered_reference_address.object_id
@f.registered_reference_address.should equal(@f.registered_reference_address)
end

describe "rb_gc_enable" do
4 changes: 2 additions & 2 deletions spec/ruby/optional/capi/string_spec.rb
Original file line number Diff line number Diff line change
@@ -188,7 +188,7 @@ def to_str
str1 = "hi"
str2 = @s.rb_str_new3 str1
str1.should == str2
str1.object_id.should_not == str2.object_id
str1.should_not equal str2
end
end

@@ -217,7 +217,7 @@ def to_str
str1 = "hi"
str2 = @s.rb_str_dup str1
str1.should == str2
str1.object_id.should_not == str2.object_id
str1.should_not equal str2
end
end