Sha256: efdbc9b0e9b6e924f7dc06e2f43f8327ea9e413b7393055c90cfa6aaf74cdacf

Contents?: true

Size: 878 Bytes

Versions: 4

Compression:

Stored size: 878 Bytes

Contents

require File.join(File.dirname(__FILE__),'../../spec_helper')

describe IMW::Formats::Json do

  before do
    @sample = IMW.open(File.join(IMWTest::DATA_DIR, 'sample.json'))
  end

  it "should be able to parse the JSON" do
    @sample.load['monkeys'].first['monkey']['id'].should == 1
  end

  it "should be able to write JSON" do
    IMW.open!('test.json').dump({ 'foobar' => 3, 'bazbooz' => 4 })
    IMW.open('test.json').load['foobar'].should == 3
  end
  
  it "should yield each key and value when the JSON is a hash and it's given a block" do
    @sample.load do |key, value|
      value.size.should == 130
    end
  end

  it "should yield each element when the JSON is an array and it's given a block" do
    IMW.open!('test.json').dump([1,2,3])
    num = 1
    IMW.open('test.json').load do |parsed_num|
      parsed_num.should == num
      num +=1
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
imw-0.2.4 spec/imw/formats/json_spec.rb
imw-0.2.3 spec/imw/formats/json_spec.rb
imw-0.2.2 spec/imw/formats/json_spec.rb
imw-0.2.1 spec/imw/formats/json_spec.rb