File: fixtures_spec.rb

package info (click to toggle)
ruby-yajl 1.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 4,036 kB
  • sloc: ansic: 3,068; ruby: 2,619; makefile: 4; sh: 3
file content (40 lines) | stat: -rw-r--r-- 1,242 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')

describe "Parsing JSON Fixtures" do
  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

  FAILED.each do |name, source|
    it "should not be able to parse #{File.basename(name)} as an IO" do
        expect {
          Yajl::Parser.parse(StringIO.new(source))
        }.to raise_error(Yajl::ParseError)
    end
  end

  FAILED.each do |name, source|
    it "should not be able to parse #{File.basename(name)} as a string" do
        expect {
          Yajl::Parser.parse(source)
        }.to raise_error(Yajl::ParseError)
    end
  end

  PASSED.each do |name, source|
    it "should be able to parse #{File.basename(name)} as an IO" do
        expect {
          Yajl::Parser.parse(StringIO.new(source))
        }.not_to raise_error
    end
  end

  PASSED.each do |name, source|
    it "should be able to parse #{File.basename(name)} as a string" do
        expect {
          Yajl::Parser.parse(source)
        }.not_to raise_error
    end
  end
end