summaryrefslogtreecommitdiff
path: root/spec/ruby/core/struct/dig_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/struct/dig_spec.rb')
-rw-r--r--spec/ruby/core/struct/dig_spec.rb14
1 files changed, 12 insertions, 2 deletions
diff --git a/spec/ruby/core/struct/dig_spec.rb b/spec/ruby/core/struct/dig_spec.rb
index 4e39e5a4ef..52e4d1dd9a 100644
--- a/spec/ruby/core/struct/dig_spec.rb
+++ b/spec/ruby/core/struct/dig_spec.rb
@@ -10,6 +10,16 @@ describe "Struct#dig" do
@instance.dig(:a, :a).should == { b: [1, 2, 3] }
end
+ it "accepts String keys" do
+ @instance.dig('a', 'a').should == { b: [1, 2, 3] }
+ end
+
+ it "returns the value by the index" do
+ instance = Struct.new(:a, :b).new(:one, :two)
+ instance.dig(0).should == :one
+ instance.dig(1).should == :two
+ end
+
it "returns the nested value specified if the sequence includes an index" do
@instance.dig(:a, :a, :b, 0).should == 1
end
@@ -22,11 +32,11 @@ describe "Struct#dig" do
instance = @klass.new(1)
-> {
instance.dig(:a, 3)
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
end
it "raises an ArgumentError if no arguments provided" do
- -> { @instance.dig }.should raise_error(ArgumentError)
+ -> { @instance.dig }.should.raise(ArgumentError)
end
it "calls #dig on any intermediate step with the rest of the sequence as arguments" do