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
|
2016-07-05 07:49:39 -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
|
|
|
|
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
|
|
|
|
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
|
|
|
|
end
|