File tree Expand file tree Collapse file tree 2 files changed +13
-7
lines changed Expand file tree Collapse file tree 2 files changed +13
-7
lines changed Original file line number Diff line number Diff line change @@ -34,18 +34,19 @@ def load_json(relative_path)
34
34
def value_at_json_path ( ruby , path )
35
35
return ruby unless path
36
36
37
- json_path_to_keys ( path ) . inject ( ruby ) do |value , key |
37
+ path . split ( "/" ) . inject ( ruby ) do |value , key |
38
38
case value
39
- when Hash , Array then value . fetch ( key ) { missing_json_path! ( path ) }
40
- else missing_json_path! ( path )
39
+ when Hash
40
+ value . fetch ( key ) { missing_json_path! ( path ) }
41
+ when Array
42
+ missing_json_path! ( path ) unless key =~ /^\d +$/
43
+ value . fetch ( key . to_i ) { missing_json_path! ( path ) }
44
+ else
45
+ missing_json_path! ( path )
41
46
end
42
47
end
43
48
end
44
49
45
- def json_path_to_keys ( path )
46
- path . split ( "/" ) . map { |k | k =~ /^\d +$/ ? k . to_i : k }
47
- end
48
-
49
50
def missing_json_path! ( path )
50
51
raise JsonSpec ::MissingPath . new ( path )
51
52
end
Original file line number Diff line number Diff line change 28
28
expect { parse_json ( json , path ) } . to raise_error ( JsonSpec ::MissingPath )
29
29
end
30
30
end
31
+
32
+ it "parses at a numeric string path" do
33
+ json = %({"1":"two"})
34
+ parse_json ( %({"1":"two"}) , "1" ) . should == "two"
35
+ end
31
36
end
32
37
33
38
context "normalize_json" do
You can’t perform that action at this time.
0 commit comments