Sha256: 2ff526c7b03d6fded248ffb2b82b5aba4cd669da2abe7a44dc431fdaac5a64fa

Contents?: true

Size: 744 Bytes

Versions: 5

Compression:

Stored size: 744 Bytes

Contents

require 'spec_helper'

describe Structure do
  context "when `structure/json' is required" do
    let(:person) { Person.new(:name => 'Joe', :age => 28) }
    let(:json) { '{"json_class":"Person","name":"Joe","age":28,"friends":[]}' }

    before do
      require 'structure/json'
    end

    it "dumps to JSON" do
      person.to_json.should eql json
    end

    it "loads from JSON" do
      JSON.parse(json).should == person
    end

    context "when nesting other structures" do
      before do
        person.friends = [Person.new(:name => 'Jane')]
      end

      it "loads them into their corresponding structures" do
        json = person.to_json
        JSON.parse(json).friends.first.should be_a Person
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
structure-0.6.0 spec/structure/json_spec.rb
structure-0.5.0 spec/structure/json_spec.rb
structure-0.4.0 spec/structure/json_spec.rb
structure-0.3.1 spec/structure/json_spec.rb
structure-0.3.0 spec/structure/json_spec.rb