Module: Spout::Tests::JsonValidation

Included in:
Spout::Tests
Defined in:
lib/spout/tests/json_validation.rb

Instance Method Summary collapse

Instance Method Details

#assert_valid_json(item, msg = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/spout/tests/json_validation.rb', line 6

def assert_valid_json(item, msg = nil)
  result = begin
    !!JSON.parse(File.read(item, encoding: "utf-8"))
  rescue JSON::ParserError => e
    error = e
    false
  end

  message = error.to_s
  assert result, message
end