Class: TC_JSONFixtures

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/vendor/json_pure/tests/test_json_fixtures.rb

Instance Method Summary collapse

Instance Method Details

#setupObject



12
13
14
15
16
17
# File 'lib/vendor/json_pure/tests/test_json_fixtures.rb', line 12

def setup
  fixtures = File.join(File.dirname(__FILE__), 'fixtures/*.json')
  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

#test_failingObject



26
27
28
29
30
31
32
33
# File 'lib/vendor/json_pure/tests/test_json_fixtures.rb', line 26

def test_failing
  for name, source in @failed
    assert_raises(JSON::ParserError, JSON::NestingError,
      "Did not fail for fixture '#{name}'") do
      JSON.parse(source)
    end
  end
end

#test_passingObject



19
20
21
22
23
24
# File 'lib/vendor/json_pure/tests/test_json_fixtures.rb', line 19

def test_passing
  for name, source in @passed
    assert JSON.parse(source),
      "Did not pass for fixture '#{name}'"
  end
end