2016-07-13 16:27:07 +03:00
|
|
|
#frozen_string_literal: false
|
2016-07-05 14:49:39 +03:00
|
|
|
require 'test_helper'
|
2015-04-12 11:36:37 +03:00
|
|
|
|
2016-07-13 16:27:07 +03:00
|
|
|
class JSONFixturesTest < Test::Unit::TestCase
|
2015-04-12 11:36:37 +03:00
|
|
|
def setup
|
2020-06-25 09:42:44 +03:00
|
|
|
fixtures = File.join(File.dirname(__FILE__), 'fixtures/{fail,pass}*.json')
|
2015-04-12 11:36:37 +03: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-03 05:45:58 +03:00
|
|
|
verbose_bak, $VERBOSE = $VERBOSE, nil
|
2015-04-12 11:36:37 +03: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-03 05:45:58 +03:00
|
|
|
ensure
|
|
|
|
$VERBOSE = verbose_bak
|
2015-04-12 11:36:37 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_failing
|
|
|
|
for name, source in @failed
|
2015-10-30 07:37:13 +03:00
|
|
|
assert_raise(JSON::ParserError, JSON::NestingError,
|
2015-04-12 11:36:37 +03:00
|
|
|
"Did not fail for fixture '#{name}': #{source.inspect}") do
|
|
|
|
JSON.parse(source)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-06-25 09:42:44 +03:00
|
|
|
|
|
|
|
def test_sanity
|
|
|
|
assert(@passed.size > 5)
|
|
|
|
assert(@failed.size > 20)
|
|
|
|
end
|
2015-04-12 11:36:37 +03:00
|
|
|
end
|