Sha256: 4a7af6f47c3e1d9b37db2acd1aa0a9f9a0a84e7afa020d1ef8e0fdc90d601d45

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

require 'spec_helper'

describe ::Rubiks::Schema do
  include_context 'schema_context'

  subject { described_class.new_from_hash }

  specify { subject.respond_to?(:from_hash) }
  specify { subject.respond_to?(:to_hash) }
  specify { subject.respond_to?(:to_json) }
  specify { subject.respond_to?(:to_xml) }
  specify { subject.respond_to?(:cubes) }

  context 'when parsed from a valid hash' do
    subject { described_class.new_from_hash(schema_hash) }

    it { should be_valid }

    its(:to_hash) { should have_key('cubes') }

    it 'has a cube' do
      subject.cubes.length.should eq 1
    end

    it 'has a Rubiks::Cube' do
      subject.cubes.first.should be_kind_of(::Rubiks::Cube)
    end

    it 'has no values' do
      subject.values.should eq([])
    end
  end

  context 'when parsed from an invalid (empty) hash' do
    subject { described_class.new_from_hash({}) }

    it { should_not be_valid }

    describe '#to_xml' do
      it 'renders XML' do
        subject.to_xml.should be_like <<-XML
        <?xml version="1.0" encoding="UTF-8"?>
        <Schema>
        </Schema>
        XML
      end
    end

    describe '#to_json' do
      it 'renders JSON' do
        subject.to_json.should be_like <<-JSON
        {}
        JSON
      end
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rubiks-0.0.4 spec/rubiks/nodes/schema_spec.rb