Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $:.unshift File.expand_path '.'
- require 'rspec'
- require 'sync_extensions'
- class DummyExtension; end
- class SomeExtension
- include Sync::Extension
- as :another
- scope(:test) { |s|
- s.domain 'expression'
- s.property :test
- s.build {}
- s.get {}
- }
- scope(:another) { |s|
- s.domain 'test'
- s.property :name
- s.build {}
- s.get {}
- }
- end
- class HighriseExtension
- include Sync::Properties
- include Sync::Extension
- as :highrise
- property :name => [:first, :last]
- document { |xml|
- xml.people { xml } # return a builder
- }
- template { |xml|
- xml.person { xml.doc }
- }
- scope(:name) { |s|
- s.domain 'first-name | last-name'
- s.property :name
- s.build {}
- s.get { |d|
- [d.at('first-name').try(:content), d.at('last-name').try(:content)]
- }
- }
- end
- describe Sync::Properties, 'module' do
- it 'should hold all properties'
- it 'should provide the property definer methods'
- end
- describe Sync::Extension, 'module' do
- subject { Sync::Extension }
- it "should hold all extensions" do
- # add a dummy extension
- subject.add(:dummy, DummyExtension)
- # check if they are managed (the auto added one too)
- subject.get(:dummy).should eql(DummyExtension)
- subject.get(:another).should eql(SomeExtension)
- end
- it 'should provide the extension builder methods' do
- SomeExtension.methods.should include(:scope, :document, :template)
- end
- end
- describe SomeExtension, 'class' do
- subject { SomeExtension }
- it 'should manage its own scopes' do
- subject.scopes.should include(:test)
- subject.scopes[:test].should be_an_instance_of(Sync::Extension::Scope)
- end
- end
- describe Sync::Extension::Scope do
- subject { SomeExtension.scopes[:test] }
- it 'should define a domain and a build and get method' do
- subject._domain.should be_an_instance_of String
- [subject._build, subject._get].all? { |f| f.should be_a_kind_of Proc }
- end
- context 'when the property does not exist' do
- it 'should raise an error' do
- expect { subject._property }.to raise_error(Sync::Properties::NoSuchProperty)
- end
- end
- context 'when the property exists' do
- it 'should know the right property' do
- SomeExtension.scopes[:another]._property.should_not be_nil
- SomeExtension.scopes[:another]._property.should eq(Sync::Properties.get(:name))
- end
- end
- end
- describe HighriseExtension, "initialized with a node" do
- DOMAIN_SIZE = 2
- def init_person_doc file
- document = Nokogiri::XML(open("samples/#{file}.xml"))
- HighriseExtension.new(document.root.at('person'))
- end
- context 'when all data is present in the document' do
- subject { init_person_doc 'highrise_contact' }
- it 'should get the right data out of the document' do
- subject.get(:name).should eq(Sync::Properties.get(:name).new('John', 'Doe'))
- end
- end
- context 'when data is partially present in the document' do
- subject { init_person_doc 'highrise_partial_contact'}
- it 'should still get the right data out of the document' do
- subject.get(:name).should eq(Sync::Properties.get(:name).new(nil, 'Doe'))
- end
- end
- context 'when the data is not present in the document'
- context 'when all data is given' do
- it 'should build the entire domain' do
- end
- end
- end
- describe HighriseExtension, "initialized with a builder" do
- before(:all) {
- @builder = Nokogiri::XML::Builder.new { |xml|
- xml.people
- }
- }
- subject { HighriseExtension.new(@builder) }
- it 'should have built a template for a data node' do
- p @builder.
- subject.node.name.should eq(:name)
- end
- end
Add Comment
Please, Sign In to add comment