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: c63ba19f7c84
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 706a4f16c2ae
Choose a head ref
  • 2 commits
  • 116 files changed
  • 1 contributor

Commits on Nov 28, 2015

  1. Squashed 'spec/ruby/' changes from 92311a8..cfdf72f

    cfdf72f add a spec that an object captured by a block, itself captured by #define_method is reachable
    9f24088 Add spec for round-tripping Time through to_r.
    882c628 incorrect string % spec - introduced at adcec1d (one too many 0s)
    41aebc0 Spec for %f with precision as a fraction.
    134753b Add more examples and assertions about $!
    b7fc313 Fix style in rescue spec
    9db1753 Expand abbreviation
    1644bc7 Add a few more examples for Float#round
    e78454c Module.remove_const returns nil when removing autoload constant
    17214e1 Specify that Module#module_eval yields the module as the first block argument
    4a44211 Organize String#unicode_normalize specs
    a4024ae Wrap lines to < 80 chars
    9ecee7a Add a note about where I took the unicode examples
    521008e Add specs for unicode_normalized?
    89d11be Add specs for exceptions
    bb6be50 Add spec for unicode_normalize!
    662fd46 Add specs for unicode_normalize
    f45bed6 add spec for Process.spawn redirecting STDERR to child STDOUT
    ffe74c3 Module#prepend is private in 2.0.0
    0f69dd1 Add a spec for the latest change in Module#prepend_features
    cc0da42 Fix file organization for String#unicode_normalize{,!,d?}
    6927f8d Add a spec to specifically test for ObjectSpace iterating singleton classes
    9f84a7f Singleton classes are walked on Ruby >= 2.3
    739ddbe Revert "singleton class is yielded"
    b8cb80b Merge pull request #163 from nobu/bug/ObjectSpace#each_object-singleton_class
    73496fa singleton class is yielded
    f724d7d Add spec for each_object(cls.singleton_class).
    60664b0 include ruby.h prior to C standard headers
    d439436 Merge pull request #160 from JuanitoFatas/ruby-23/core/hash-comparison
    7f3b584 [Core/hash] Add specs for Hash #<=, #>=, #<, #> for Ruby 2.3
    1a1fcb6 Literal strings as literal hash keys must preserve encoding.
    ea1335c Add examples to specify #dig calls
    c0a4a73 Merge pull request #161 from kares/master
    788bb96 add a nested missing Hash key retrieval assert
    fd7383a clarify Array#at method is meant in spec desc
    d9f2120 Remove extra dot
    94d39de Fix typos in Hash#to_proc spec
    a1a040a Get rid of sleep in require specs and just synchronize instead
    f94fff6 Remove usage of sleep in Process.wait spec
    907c462 Remove usage of sleep in IO#select spec
    bfc40c3 NetFTPSpecs::DummyFTP should not use hardcoded port number.
    5607f17 Remove trailing whitespace from description
    f039c77 Add "Enumerator" to "#enum_for" and "#to_enum" descriptions
    643a506 tag dig specs with ruby_version_is 2.3
    5473e04 spec nested type-mixed dig behaviour (including raw def-d obj.dig) on Ruby 2.3
    ce93264 [core/hash] Hash#dig feature specs for Ruby 2.3
    8600c67 [core/array] invented some Array#dig specs for Ruby 2.3
    5f89c6d Add String# to the unicode_normalized? description
    175c53e Merge pull request #159 from kachick/hash-to_proc
    e97d589 Write Hash#to_proc specs
    9686345 Merge pull request #158 from shugo/master
    03a6d80 Check whether Net::FTP.default_passive is defined.
    9b8931a Set Net::FTP.default_passive to false.
    971924f Like FreeBSD, such simple spec can't pass on Solaris.
    1f9b065 Socket option shoud be set as CRuby's test does.
    cfbd946 Ruby 2.3 changes the default of Net::HTTP#open_timeout at r52480
    1dab981 Fix typo in Marshal#load specdoc
    73c4c70 Do not rely on stdlib in core Marshal specs
    5b6334e Remove old duplicated fixture file
    e7a5299 Merge Marshal fixtures for 1.9 with common fixtures
    dc53709 Some plaftorms do not have Dir#fileno
    3fcbce7 Remove rare case because rubyspec is not tzdata-spec
    bdd83f3 Use File.realpath in case /dev/null is symlink like i386-solaris
    e5ee977 Revert "/dev/null is symbolic link on i386-solaris"
    11f13e4 Add more specs for a Method generated with respond_to_missing?
    999d719 Remove dead code
    bc7db44 Do not rely on any order for directory entries.
    14b420f don't test features solaris doesn't support
    89c50a2 /dev/null is symbolic link on i386-solaris
    46d97ad don't run timezone rare case on Solaris
    63b52ac Solaris doesn't have http definition in services by default
    9940991 Solaris's syslog related constants are also different
    3816a19 pow(3) behavior depends on compile-time options on Solaris.
    
    git-subtree-dir: spec/ruby
    git-subtree-split: cfdf72f32b206cf170e9de479e2cff1d79c8865e
    eregon committed Nov 28, 2015
    Copy the full SHA
    c2d00dd View commit details
  2. Copy the full SHA
    706a4f1 View commit details
Showing with 890 additions and 447 deletions.
  1. +29 −0 spec/ruby/core/array/dig_spec.rb
  2. +3 −3 spec/ruby/core/dir/entries_spec.rb
  3. +14 −7 spec/ruby/core/dir/fileno_spec.rb
  4. +1 −1 spec/ruby/core/enumerator/enum_for_spec.rb
  5. +1 −1 spec/ruby/core/enumerator/size_spec.rb
  6. +1 −1 spec/ruby/core/enumerator/to_enum_spec.rb
  7. +0 −6 spec/ruby/core/file/stat/zero_spec.rb
  8. +47 −0 spec/ruby/core/hash/dig_spec.rb
  9. +32 −0 spec/ruby/core/hash/gt_spec.rb
  10. +32 −0 spec/ruby/core/hash/gte_spec.rb
  11. +32 −0 spec/ruby/core/hash/lt_spec.rb
  12. +32 −0 spec/ruby/core/hash/lte_spec.rb
  13. +53 −0 spec/ruby/core/hash/to_proc_spec.rb
  14. +13 −19 spec/ruby/core/io/select_spec.rb
  15. +0 −5 spec/ruby/core/kernel/shared/method.rb
  16. +31 −46 spec/ruby/core/kernel/shared/require.rb
  17. +0 −1 spec/ruby/core/marshal/dump_spec.rb
  18. +6 −16 spec/ruby/core/marshal/fixtures/marshal_data.rb
  19. +0 −7 spec/ruby/core/marshal/fixtures/marshal_data19.rb
  20. +19 −7 spec/ruby/core/marshal/shared/load.rb
  21. +26 −1 spec/ruby/core/method/shared/call.rb
  22. +22 −0 spec/ruby/core/module/prepend_features_spec.rb
  23. +50 −0 spec/ruby/core/objectspace/each_object_spec.rb
  24. +5 −0 spec/ruby/core/objectspace/fixtures.rb
  25. +9 −5 spec/ruby/core/process/wait_spec.rb
  26. +118 −0 spec/ruby/core/string/unicode_normalize_spec.rb
  27. +29 −53 spec/ruby/core/string/unicode_normalized_spec.rb
  28. +0 −14 spec/ruby/core/time/shared/local.rb
  29. +6 −2 spec/ruby/fixtures/code/concurrent.rb
  30. +7 −1 spec/ruby/fixtures/code/concurrent2.rb
  31. +2 −1 spec/ruby/fixtures/code/concurrent3.rb
  32. +0 −40 spec/ruby/fixtures/thread_runner.rb
  33. +7 −0 spec/ruby/language/fixtures/hash_strings_ascii8bit.rb
  34. +7 −0 spec/ruby/language/fixtures/hash_strings_usascii.rb
  35. +7 −0 spec/ruby/language/fixtures/hash_strings_utf8.rb
  36. +0 −22 spec/ruby/language/fixtures/return19.rb
  37. +14 −0 spec/ruby/language/hash_spec.rb
  38. +2 −2 spec/ruby/library/net/ftp/abort_spec.rb
  39. +2 −2 spec/ruby/library/net/ftp/acct_spec.rb
  40. +1 −1 spec/ruby/library/net/ftp/binary_spec.rb
  41. +2 −2 spec/ruby/library/net/ftp/chdir_spec.rb
  42. +1 −1 spec/ruby/library/net/ftp/close_spec.rb
  43. +1 −1 spec/ruby/library/net/ftp/closed_spec.rb
  44. +7 −7 spec/ruby/library/net/ftp/connect_spec.rb
  45. +1 −1 spec/ruby/library/net/ftp/debug_mode_spec.rb
  46. +2 −2 spec/ruby/library/net/ftp/delete_spec.rb
  47. +1 −1 spec/ruby/library/net/ftp/dir_spec.rb
  48. +10 −2 spec/ruby/library/net/ftp/fixtures/server.rb
  49. +1 −1 spec/ruby/library/net/ftp/get_spec.rb
  50. +1 −1 spec/ruby/library/net/ftp/getbinaryfile_spec.rb
  51. +1 −1 spec/ruby/library/net/ftp/getdir_spec.rb
  52. +1 −1 spec/ruby/library/net/ftp/gettextfile_spec.rb
  53. +2 −2 spec/ruby/library/net/ftp/help_spec.rb
  54. +1 −1 spec/ruby/library/net/ftp/initialize_spec.rb
  55. +1 −1 spec/ruby/library/net/ftp/last_response_code_spec.rb
  56. +2 −2 spec/ruby/library/net/ftp/last_response_spec.rb
  57. +1 −1 spec/ruby/library/net/ftp/lastresp_spec.rb
  58. +1 −1 spec/ruby/library/net/ftp/list_spec.rb
  59. +2 −2 spec/ruby/library/net/ftp/login_spec.rb
  60. +1 −1 spec/ruby/library/net/ftp/ls_spec.rb
  61. +2 −2 spec/ruby/library/net/ftp/mdtm_spec.rb
  62. +2 −2 spec/ruby/library/net/ftp/mkdir_spec.rb
  63. +2 −2 spec/ruby/library/net/ftp/mtime_spec.rb
  64. +2 −2 spec/ruby/library/net/ftp/nlst_spec.rb
  65. +2 −2 spec/ruby/library/net/ftp/noop_spec.rb
  66. +1 −1 spec/ruby/library/net/ftp/open_spec.rb
  67. +1 −1 spec/ruby/library/net/ftp/passive_spec.rb
  68. +1 −1 spec/ruby/library/net/ftp/put_spec.rb
  69. +1 −1 spec/ruby/library/net/ftp/putbinaryfile_spec.rb
  70. +1 −1 spec/ruby/library/net/ftp/puttextfile_spec.rb
  71. +2 −2 spec/ruby/library/net/ftp/pwd_spec.rb
  72. +2 −2 spec/ruby/library/net/ftp/quit_spec.rb
  73. +2 −2 spec/ruby/library/net/ftp/rename_spec.rb
  74. +1 −1 spec/ruby/library/net/ftp/resume_spec.rb
  75. +2 −2 spec/ruby/library/net/ftp/retrbinary_spec.rb
  76. +2 −2 spec/ruby/library/net/ftp/retrlines_spec.rb
  77. +1 −1 spec/ruby/library/net/ftp/return_code_spec.rb
  78. +2 −2 spec/ruby/library/net/ftp/rmdir_spec.rb
  79. +2 −2 spec/ruby/library/net/ftp/sendcmd_spec.rb
  80. +1 −1 spec/ruby/library/net/ftp/set_socket_spec.rb
  81. +1 −1 spec/ruby/library/net/ftp/shared/getbinaryfile.rb
  82. +1 −1 spec/ruby/library/net/ftp/shared/gettextfile.rb
  83. +1 −1 spec/ruby/library/net/ftp/shared/last_response_code.rb
  84. +1 −1 spec/ruby/library/net/ftp/shared/list.rb
  85. +1 −1 spec/ruby/library/net/ftp/shared/putbinaryfile.rb
  86. +1 −1 spec/ruby/library/net/ftp/shared/puttextfile.rb
  87. +2 −2 spec/ruby/library/net/ftp/site_spec.rb
  88. +2 −2 spec/ruby/library/net/ftp/size_spec.rb
  89. +5 −0 spec/ruby/library/net/ftp/spec_helper.rb
  90. +2 −2 spec/ruby/library/net/ftp/status_spec.rb
  91. +2 −2 spec/ruby/library/net/ftp/storbinary_spec.rb
  92. +2 −2 spec/ruby/library/net/ftp/storlines_spec.rb
  93. +2 −2 spec/ruby/library/net/ftp/system_spec.rb
  94. +2 −2 spec/ruby/library/net/ftp/voidcmd_spec.rb
  95. +2 −2 spec/ruby/library/net/ftp/welcome_spec.rb
  96. +16 −5 spec/ruby/library/net/http/http/open_timeout_spec.rb
  97. +19 −17 spec/ruby/library/socket/basicsocket/recv_spec.rb
  98. +20 −18 spec/ruby/library/socket/basicsocket/send_spec.rb
  99. +10 −1 spec/ruby/library/socket/constants/constants_spec.rb
  100. +1 −1 spec/ruby/library/socket/socket/connect_nonblock_spec.rb
  101. +17 −17 spec/ruby/library/socket/socket/getaddrinfo_spec.rb
  102. +6 −6 spec/ruby/library/socket/socket/getnameinfo_spec.rb
  103. +4 −4 spec/ruby/library/socket/socket/getservbyname_spec.rb
  104. +1 −1 spec/ruby/library/syslog/constants_spec.rb
  105. +3 −3 spec/ruby/optional/capi/ext/class_spec.c
  106. +2 −2 spec/ruby/optional/capi/ext/data_spec.c
  107. +3 −3 spec/ruby/optional/capi/ext/exception_spec.c
  108. +2 −2 spec/ruby/optional/capi/ext/float_spec.c
  109. +2 −2 spec/ruby/optional/capi/ext/kernel_spec.c
  110. +2 −2 spec/ruby/optional/capi/ext/proc_spec.c
  111. +2 −2 spec/ruby/optional/capi/ext/string_spec.c
  112. +4 −4 spec/ruby/optional/capi/ext/thread_spec.c
  113. +2 −2 spec/ruby/optional/capi/ext/typed_data_spec.c
  114. +2 −2 spec/ruby/shared/file/zero.rb
  115. +8 −0 spec/ruby/shared/process/spawn.rb
  116. +5 −3 spec/ruby/shared/rational/exponent.rb
29 changes: 29 additions & 0 deletions spec/ruby/core/array/dig_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require File.expand_path('../../../spec_helper', __FILE__)

ruby_version_is '2.3' do
describe "Array#dig" do

it "returns #at with one arg" do
['a'].dig(0).should == 'a'
['a'].dig(1).should be_nil
end

it "recurses array elements" do
a = [ [ 1, [2, '3'] ] ]
a.dig(0, 0).should == 1
a.dig(0, 1, 1).should == '3'
a.dig(0, -1, 0).should == 2
end

it "raises without any args" do
lambda { [10].dig() }.should raise_error(ArgumentError)
end

it "calls #dig on the result of #at with the remaining arguments" do
h = [[nil, [nil, nil, 42]]]
h[0].should_receive(:dig).with(1, 2).and_return(42)
h.dig(0, 1, 2).should == 42
end

end
end
6 changes: 3 additions & 3 deletions spec/ruby/core/dir/entries_spec.rb
Original file line number Diff line number Diff line change
@@ -43,7 +43,7 @@
it "returns entries encoded with the filesystem encoding by default" do
# This spec depends on the locale not being US-ASCII because if it is, the
# entries that are not ascii_only? will be ASCII-8BIT encoded.
entries = Dir.entries File.join(DirSpecs.mock_dir, 'special')
entries = Dir.entries(File.join(DirSpecs.mock_dir, 'special')).sort
encoding = Encoding.find("filesystem")
encoding = Encoding::ASCII_8BIT if encoding == Encoding::US_ASCII
entries.should include("こんにちは.txt".force_encoding(encoding))
@@ -52,13 +52,13 @@

it "returns entries encoded with the specified encoding" do
dir = File.join(DirSpecs.mock_dir, 'special')
entries = Dir.entries dir, encoding: "euc-jp"
entries = Dir.entries(dir, encoding: "euc-jp").sort
entries.first.encoding.should equal(Encoding::EUC_JP)
end

it "returns entries transcoded to the default internal encoding" do
Encoding.default_internal = Encoding::EUC_KR
entries = Dir.entries File.join(DirSpecs.mock_dir, 'special')
entries = Dir.entries(File.join(DirSpecs.mock_dir, 'special')).sort
entries.first.encoding.should equal(Encoding::EUC_KR)
end

21 changes: 14 additions & 7 deletions spec/ruby/core/dir/fileno_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/common', __FILE__)

has_dir_fileno = begin
Dir.new('.').fileno
true
rescue NotImplementedError
false
rescue Exception
true
end

ruby_version_is "2.2" do
describe "Dir#fileno" do
before :each do
@@ -14,15 +23,13 @@
rm_r @name
end

platform_is_not :windows do
if has_dir_fileno
it "returns the file descriptor of the dir" do
@dir.fileno.should.be_kind_of(Fixnum)
@dir.fileno.should be_kind_of(Fixnum)
end
end

platform_is :windows do
it "raises an error on Windows" do
lambda { @dir.fileno }.to raise_error(NotImplementedError)
else
it "raises an error when not implemented on the platform" do
lambda { @dir.fileno }.should raise_error(NotImplementedError)
end
end
end
2 changes: 1 addition & 1 deletion spec/ruby/core/enumerator/enum_for_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../../../shared/enumerator/enum_for', __FILE__)

describe "#enum_for" do
describe "Enumerator#enum_for" do
it_behaves_like :enum_for, :enum_for
end
2 changes: 1 addition & 1 deletion spec/ruby/core/enumerator/size_spec.rb
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@
end

ruby_version_is "2.1" do
it "returns the result from size.call if the size respond to call " do
it "returns the result from size.call if the size respond to call" do
obj = mock('call')
obj.should_receive(:call).and_return(42)
Enumerator.new(obj) {}.size.should == 42
2 changes: 1 addition & 1 deletion spec/ruby/core/enumerator/to_enum_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../../../shared/enumerator/enum_for', __FILE__)

describe "#to_enum" do
describe "Enumerator#to_enum" do
it_behaves_like :enum_for, :enum_for
end
6 changes: 0 additions & 6 deletions spec/ruby/core/file/stat/zero_spec.rb
Original file line number Diff line number Diff line change
@@ -4,10 +4,4 @@

describe "File::Stat#zero?" do
it_behaves_like :file_zero, :zero?, FileStat

platform_is :solaris do
it "returns false for /dev/null" do
FileStat.zero?('/dev/null').should == false
end
end
end
47 changes: 47 additions & 0 deletions spec/ruby/core/hash/dig_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
require File.expand_path('../../../spec_helper', __FILE__)

ruby_version_is '2.3' do
describe "Hash#dig" do

it "returns #[] with one arg" do
h = { 0 => false, :a => 1 }
h.dig(:a).should == 1
h.dig(0).should be_false
h.dig(1).should be_nil
end

it "does recurse" do
h = { foo: { bar: { baz: 1 } } }
h.dig(:foo, :bar, :baz).should == 1
h.dig(:foo, :bar, :nope).should be_nil
h.dig(:foo, :baz).should be_nil
h.dig(:bar, :baz, :foo).should be_nil
end

it "raises without args" do
lambda { { the: 'borg' }.dig() }.should raise_error(ArgumentError)
end

it "handles type-mixed deep digging" do
h = {}
h[:foo] = [ { :bar => [ 1 ] }, [ obj = Object.new, 'str' ] ]
def obj.dig(*args); [ 42 ] end

h.dig(:foo, 0, :bar).should == [ 1 ]
h.dig(:foo, 0, :bar, 0).should == 1
h.dig(:foo, 0, :bar, 0, 0).should be_nil
h.dig(:foo, 1, 1).should == 'str'
h.dig(:foo, 1, 1, 0).should be_nil
# MRI does not recurse values returned from `obj.dig`
h.dig(:foo, 1, 0, 0).should == [ 42 ]
h.dig(:foo, 1, 0, 0, 10).should == [ 42 ]
end

it "calls #dig on the result of #[] with the remaining arguments" do
h = { foo: { bar: { baz: 42 } } }
h[:foo].should_receive(:dig).with(:bar, :baz).and_return(42)
h.dig(:foo, :bar, :baz).should == 42
end

end
end
32 changes: 32 additions & 0 deletions spec/ruby/core/hash/gt_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require File.expand_path('../../../spec_helper', __FILE__)

ruby_version_is "2.3" do
describe "Hash#>" do
before :each do
@hash = {a:1, b:2}
@bigger = {a:1, b:2, c:3}
@unrelated = {c:3, d:4}
@similar = {a:2, b:3}
end

it "returns false when receiver size is smaller than argument" do
(@hash > @bigger).should == false
(@unrelated > @bigger).should == false
end

it "returns false when receiver size is the same as argument" do
(@hash > @hash).should == false
(@hash > @unrelated).should == false
(@unrelated > @hash).should == false
end

it "returns true when argument is a subset of receiver" do
(@bigger > @hash).should == true
end

it "returns false when keys match but values don't" do
(@hash > @similar).should == false
(@similar > @hash).should == false
end
end
end
32 changes: 32 additions & 0 deletions spec/ruby/core/hash/gte_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require File.expand_path('../../../spec_helper', __FILE__)

ruby_version_is "2.3" do
describe "Hash#>=" do
before :each do
@hash = {a:1, b:2}
@bigger = {a:1, b:2, c:3}
@unrelated = {c:3, d:4}
@similar = {a:2, b:3}
end

it "returns false when receiver size is smaller than argument" do
(@hash >= @bigger).should == false
(@unrelated >= @bigger).should == false
end

it "returns false when argument is not a subset or not equals to receiver" do
(@hash >= @unrelated).should == false
(@unrelated >= @hash).should == false
end

it "returns true when argument is a subset of receiver or equals to receiver" do
(@bigger >= @hash).should == true
(@hash >= @hash).should == true
end

it "returns false when keys match but values don't" do
(@hash >= @similar).should == false
(@similar >= @hash).should == false
end
end
end
32 changes: 32 additions & 0 deletions spec/ruby/core/hash/lt_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require File.expand_path('../../../spec_helper', __FILE__)

ruby_version_is "2.3" do
describe "Hash#<" do
before :each do
@hash = {a:1, b:2}
@bigger = {a:1, b:2, c:3}
@unrelated = {c:3, d:4}
@similar = {a:2, b:3}
end

it "returns false when receiver size is larger than argument" do
(@bigger < @hash).should == false
(@bigger < @unrelated).should == false
end

it "returns false when receiver size is the same as argument" do
(@hash < @hash).should == false
(@hash < @unrelated).should == false
(@unrelated < @hash).should == false
end

it "returns true when receiver is a subset of argument" do
(@hash < @bigger).should == true
end

it "returns false when keys match but values don't" do
(@hash < @similar).should == false
(@similar < @hash).should == false
end
end
end
32 changes: 32 additions & 0 deletions spec/ruby/core/hash/lte_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require File.expand_path('../../../spec_helper', __FILE__)

ruby_version_is "2.3" do
describe "Hash#<=" do
before :each do
@hash = {a:1, b:2}
@bigger = {a:1, b:2, c:3}
@unrelated = {c:3, d:4}
@similar = {a:2, b:3}
end

it "returns false when receiver size is larger than argument" do
(@bigger <= @hash).should == false
(@bigger <= @unrelated).should == false
end

it "returns false when receiver size is the same as argument" do
(@hash <= @unrelated).should == false
(@unrelated <= @hash).should == false
end

it "returns true when receiver is a subset of argument or equals to argument" do
(@hash <= @bigger).should == true
(@hash <= @hash).should == true
end

it "returns false when keys match but values don't" do
(@hash <= @similar).should == false
(@similar <= @hash).should == false
end
end
end
53 changes: 53 additions & 0 deletions spec/ruby/core/hash/to_proc_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)

ruby_version_is "2.3" do
describe "Hash#to_proc" do
before :each do
@key = Object.new
@value = Object.new
@hash = new_hash @key => @value
@default = Object.new
@unstored = Object.new
end

it "returns an instance of Proc" do
@hash.to_proc.should be_an_instance_of Proc
end

describe "the returned proc" do
before :each do
@proc = @hash.to_proc
end

context "with a stored key" do
it "returns the paired value" do
@proc.call(@key).should equal(@value)
end
end

context "with no stored key" do
it "returns nil" do
@proc.call(@unstored).should be_nil
end

context "when the hash has a default value" do
before :each do
@hash.default = @default
end

it "returns the default value" do
@proc.call(@unstored).should equal(@default)
end
end

context "when the hash has a default proc" do
it "returns an evaluated value from the default proc" do
@hash.default_proc = -> hash, called_with { [hash.keys, called_with] }
@proc.call(@unstored).should == [[@key], @unstored]
end
end
end
end
end
end
Loading