File tree Expand file tree Collapse file tree 2 files changed +53
-0
lines changed Expand file tree Collapse file tree 2 files changed +53
-0
lines changed Original file line number Diff line number Diff line change
1
+ require_relative '../../spec_helper'
2
+ require_relative 'fixtures/classes'
3
+
4
+ ruby_version_is "2.7" do
5
+ describe "Hash.ruby2_keywords_hash?" do
6
+ it "returns false if the Hash is not a keywords Hash" do
7
+ Hash . ruby2_keywords_hash? ( { } ) . should == false
8
+ end
9
+
10
+ it "returns true if the Hash is a keywords Hash" do
11
+ obj = Class . new {
12
+ ruby2_keywords def m ( *args )
13
+ args . last
14
+ end
15
+ } . new
16
+ Hash . ruby2_keywords_hash? ( obj . m ( a : 1 ) ) . should == true
17
+ end
18
+
19
+ it "raises TypeError for non-Hash" do
20
+ -> { Hash . ruby2_keywords_hash? ( nil ) } . should raise_error ( TypeError )
21
+ end
22
+ end
23
+
24
+ describe "Hash.ruby2_keywords_hash" do
25
+ it "returns a copy of a Hash and marks the copy as a keywords Hash" do
26
+ h = { a : 1 } . freeze
27
+ kw = Hash . ruby2_keywords_hash ( h )
28
+ Hash . ruby2_keywords_hash? ( h ) . should == false
29
+ Hash . ruby2_keywords_hash? ( kw ) . should == true
30
+ kw . should == h
31
+ end
32
+
33
+ it "returns an instance of the subclass if called on an instance of a subclass of Hash" do
34
+ h = HashSpecs ::MyHash . new
35
+ h [ :a ] = 1
36
+ kw = Hash . ruby2_keywords_hash ( h )
37
+ kw . class . should == HashSpecs ::MyHash
38
+ Hash . ruby2_keywords_hash? ( h ) . should == false
39
+ Hash . ruby2_keywords_hash? ( kw ) . should == true
40
+ kw . should == h
41
+ end
42
+
43
+ it "raises TypeError for non-Hash" do
44
+ -> { Hash . ruby2_keywords_hash ( nil ) } . should raise_error ( TypeError )
45
+ end
46
+ end
47
+ end
Original file line number Diff line number Diff line change
1
+ fails:Hash.ruby2_keywords_hash? returns false if the Hash is not a keywords Hash
2
+ fails:Hash.ruby2_keywords_hash? returns true if the Hash is a keywords Hash
3
+ fails:Hash.ruby2_keywords_hash? raises TypeError for non-Hash
4
+ fails:Hash.ruby2_keywords_hash returns a copy of a Hash and marks the copy as a keywords Hash
5
+ fails:Hash.ruby2_keywords_hash raises TypeError for non-Hash
6
+ fails:Hash.ruby2_keywords_hash returns an instance of the subclass if called on an instance of a subclass of Hash
You can’t perform that action at this time.
0 commit comments