Guest User

Untitled

a guest
Dec 11th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.73 KB | None | 0 0
  1. $:.unshift File.expand_path '.'
  2.  
  3. require 'rspec'
  4. require 'sync_extensions'
  5.  
  6. class DummyExtension; end
  7.  
  8. class SomeExtension
  9. include Sync::Extension
  10. as :another
  11.  
  12. scope(:test) { |s|
  13. s.domain 'expression'
  14. s.property :test
  15.  
  16. s.build {}
  17. s.get {}
  18. }
  19.  
  20. scope(:another) { |s|
  21. s.domain 'test'
  22. s.property :name
  23.  
  24. s.build {}
  25. s.get {}
  26. }
  27. end
  28.  
  29. class HighriseExtension
  30. include Sync::Properties
  31. include Sync::Extension
  32. as :highrise
  33.  
  34. property :name => [:first, :last]
  35.  
  36. document { |xml|
  37. xml.people { xml } # return a builder
  38. }
  39.  
  40. template { |xml|
  41. xml.person { xml.doc }
  42. }
  43.  
  44. scope(:name) { |s|
  45. s.domain 'first-name | last-name'
  46. s.property :name
  47.  
  48. s.build {}
  49. s.get { |d|
  50. [d.at('first-name').try(:content), d.at('last-name').try(:content)]
  51. }
  52. }
  53. end
  54.  
  55. describe Sync::Properties, 'module' do
  56. it 'should hold all properties'
  57. it 'should provide the property definer methods'
  58. end
  59.  
  60. describe Sync::Extension, 'module' do
  61. subject { Sync::Extension }
  62.  
  63. it "should hold all extensions" do
  64. # add a dummy extension
  65. subject.add(:dummy, DummyExtension)
  66. # check if they are managed (the auto added one too)
  67. subject.get(:dummy).should eql(DummyExtension)
  68. subject.get(:another).should eql(SomeExtension)
  69. end
  70.  
  71. it 'should provide the extension builder methods' do
  72. SomeExtension.methods.should include(:scope, :document, :template)
  73. end
  74. end
  75.  
  76. describe SomeExtension, 'class' do
  77. subject { SomeExtension }
  78.  
  79. it 'should manage its own scopes' do
  80. subject.scopes.should include(:test)
  81. subject.scopes[:test].should be_an_instance_of(Sync::Extension::Scope)
  82. end
  83. end
  84.  
  85. describe Sync::Extension::Scope do
  86. subject { SomeExtension.scopes[:test] }
  87.  
  88. it 'should define a domain and a build and get method' do
  89. subject._domain.should be_an_instance_of String
  90. [subject._build, subject._get].all? { |f| f.should be_a_kind_of Proc }
  91. end
  92.  
  93. context 'when the property does not exist' do
  94. it 'should raise an error' do
  95. expect { subject._property }.to raise_error(Sync::Properties::NoSuchProperty)
  96. end
  97. end
  98.  
  99. context 'when the property exists' do
  100. it 'should know the right property' do
  101. SomeExtension.scopes[:another]._property.should_not be_nil
  102. SomeExtension.scopes[:another]._property.should eq(Sync::Properties.get(:name))
  103. end
  104. end
  105. end
  106.  
  107. describe HighriseExtension, "initialized with a node" do
  108. DOMAIN_SIZE = 2
  109.  
  110. def init_person_doc file
  111. document = Nokogiri::XML(open("samples/#{file}.xml"))
  112. HighriseExtension.new(document.root.at('person'))
  113. end
  114.  
  115. context 'when all data is present in the document' do
  116. subject { init_person_doc 'highrise_contact' }
  117.  
  118. it 'should get the right data out of the document' do
  119. subject.get(:name).should eq(Sync::Properties.get(:name).new('John', 'Doe'))
  120. end
  121. end
  122.  
  123. context 'when data is partially present in the document' do
  124. subject { init_person_doc 'highrise_partial_contact'}
  125.  
  126. it 'should still get the right data out of the document' do
  127. subject.get(:name).should eq(Sync::Properties.get(:name).new(nil, 'Doe'))
  128. end
  129. end
  130.  
  131. context 'when the data is not present in the document'
  132.  
  133. context 'when all data is given' do
  134. it 'should build the entire domain' do
  135.  
  136. end
  137. end
  138. end
  139.  
  140. describe HighriseExtension, "initialized with a builder" do
  141. before(:all) {
  142. @builder = Nokogiri::XML::Builder.new { |xml|
  143. xml.people
  144. }
  145. }
  146.  
  147. subject { HighriseExtension.new(@builder) }
  148.  
  149. it 'should have built a template for a data node' do
  150. p @builder.
  151. subject.node.name.should eq(:name)
  152. end
  153. end
Add Comment
Please, Sign In to add comment