2016-07-13 09:27:07 -04:00
|
|
|
#frozen_string_literal: false
|
2016-07-05 07:49:39 -04:00
|
|
|
require 'test_helper'
|
2015-04-12 04:36:37 -04:00
|
|
|
|
2016-07-13 09:27:07 -04:00
|
|
|
class JSONFixturesTest < Test::Unit::TestCase
|
2015-04-12 04:36:37 -04:00
|
|
|
def setup
|
2020-06-25 02:42:44 -04:00
|
|
|
fixtures = File.join(File.dirname(__FILE__), 'fixtures/{fail,pass}*.json')
|
2015-04-12 04:36:37 -04:00
|
|
|
passed, failed = Dir[fixtures].partition { |f| f['pass'] }
|
|
|
|
@passed = passed.inject([]) { |a, f| a << [ f, File.read(f) ] }.sort
|
|
|
|
@failed = failed.inject([]) { |a, f| a << [ f, File.read(f) ] }.sort
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_passing
|
2020-07-02 22:45:58 -04:00
|
|
|
verbose_bak, $VERBOSE = $VERBOSE, nil
|
2015-04-12 04:36:37 -04:00
|
|
|
for name, source in @passed
|
|
|
|
begin
|
|
|
|
assert JSON.parse(source),
|
|
|
|
"Did not pass for fixture '#{name}': #{source.inspect}"
|
|
|
|
rescue => e
|
|
|
|
warn "\nCaught #{e.class}(#{e}) for fixture '#{name}': #{source.inspect}\n#{e.backtrace * "\n"}"
|
|
|
|
raise e
|
|
|
|
end
|
|
|
|
end
|
2020-07-02 22:45:58 -04:00
|
|
|
ensure
|
|
|
|
$VERBOSE = verbose_bak
|
2015-04-12 04:36:37 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_failing
|
|
|
|
for name, source in @failed
|
2015-10-30 00:37:13 -04:00
|
|
|
assert_raise(JSON::ParserError, JSON::NestingError,
|
2015-04-12 04:36:37 -04:00
|
|
|
"Did not fail for fixture '#{name}': #{source.inspect}") do
|
|
|
|
JSON.parse(source)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-06-25 02:42:44 -04:00
|
|
|
|
|
|
|
def test_sanity
|
|
|
|
assert(@passed.size > 5)
|
|
|
|
assert(@failed.size > 20)
|
|
|
|
end
|
2015-04-12 04:36:37 -04:00
|
|
|
end
|