Skip to content

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

stdlib/json/0/json.rbs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,28 @@ module JSON
980980
#
981981
def self?.load: (string | _JsonReadableIO | _JsonRead source, ?Proc proc, ?json_options options) -> untyped
982982

983+
# <!--
984+
# rdoc-file=ext/json/lib/json/common.rb
985+
# - JSON.load_file(path, opts={}) -> object
986+
# -->
987+
# Calls:
988+
# parse(File.read(path), opts)
989+
#
990+
# See method #parse.
991+
#
992+
def self?.load_file: (string path, ?json_options opts) -> untyped
993+
994+
# <!--
995+
# rdoc-file=ext/json/lib/json/common.rb
996+
# - JSON.load_file!(path, opts = {})
997+
# -->
998+
# Calls:
999+
# JSON.parse!(File.read(path, opts))
1000+
#
1001+
# See method #parse!
1002+
#
1003+
def self?.load_file!: (string path, ?json_options opts) -> untyped
1004+
9831005
# <!-- rdoc-file=ext/json/lib/json/common.rb -->
9841006
# Sets or returns default options for the JSON.load method. Initially:
9851007
# opts = JSON.load_default_options

test/stdlib/json/JSON_test.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require_relative "../test_helper"
22
require "json"
3+
require "tempfile"
34

45
class JsonToStr
56
def initialize(value = "")
@@ -108,6 +109,26 @@ def test_load
108109
assert_send_type "(String, Proc, Hash[untyped, untyped]) -> 42", JSON, :load, "42", proc { }, { alllow_nan: true }
109110
end
110111

112+
def test_load_file
113+
Tempfile.create("json") do |f|
114+
f.write '{}'
115+
f.close
116+
117+
assert_send_type "(String) -> untyped", JSON, :load_file, f.path
118+
assert_send_type "(String, Hash[untyped, untyped]) -> untyped", JSON, :load_file, f.path, { allow_nan: true }
119+
end
120+
end
121+
122+
def test_load_file!
123+
Tempfile.create("json") do |f|
124+
f.write '{}'
125+
f.close
126+
127+
assert_send_type "(String) -> untyped", JSON, :load_file!, f.path
128+
assert_send_type "(String, Hash[untyped, untyped]) -> untyped", JSON, :load_file!, f.path, { allow_nan: true }
129+
end
130+
end
131+
111132
def test_load_default_options
112133
assert_send_type "() -> Hash[untyped, untyped]", JSON, :load_default_options
113134
end

0 commit comments

Comments
 (0)