spec/blather/stanza/x_spec.rb in blather-0.4.10 vs spec/blather/stanza/x_spec.rb in blather-0.4.11

- old
+ new

@@ -13,16 +13,16 @@ type='text-single' label='description' /> <field var='field-name3' type='text-single' label='description' /> - <field var='field-name' - type='{field-type}' + <field var='field-name4' + type='list-multi' label='description'> <desc/> <required/> - <value>field-value</value> + <value>field-value4</value> <option label='option-label'><value>option-value</value></option> <option label='option-label'><value>option-value</value></option> </field> </x> XML @@ -79,10 +79,17 @@ r = Blather::Stanza::X.new.inherit n.form r.fields.size.must_equal 4 r.fields.map { |f| f.class }.uniq.must_equal [Blather::Stanza::X::Field] end + it 'returns a field object for a particular var' do + x = Blather::Stanza::X.new parse_stanza(x_xml).root + f = x.field 'field-name4' + f.must_be_instance_of Blather::Stanza::X::Field + f.value.must_equal 'field-value4' + end + it 'takes a list of hashes for fields' do fields = [ {:label => 'label', :type => 'text-single', :var => 'var'}, {:label => 'label1', :type => 'text-single', :var => 'var1'}, ] @@ -119,13 +126,13 @@ end it 'allows adding of fields' do di = Blather::Stanza::X.new nil di.fields.size.must_equal 0 - di.add_fields [{:label => 'label', :type => 'text-single', :var => 'var'}] + di.fields = [{:label => 'label', :type => 'text-single', :var => 'var', :required => true}] di.fields.size.must_equal 1 - di.add_fields [Blather::Stanza::X::Field.new(*%w[text-single var1 label1])] + di.fields += [Blather::Stanza::X::Field.new(*%w[text-single var1 label1])] di.fields.size.must_equal 2 end end @@ -169,13 +176,13 @@ end it 'has a required? attribute' do n = Blather::Stanza::X::Field.new 'text-single', 'subject', 'Music from the time of Shakespeare' n.required?.must_equal false - n.required! + n.required = true n.required?.must_equal true - n.required! false + n.required = false n.required?.must_equal false end it 'has a value attribute' do n = Blather::Stanza::X::Field.new 'text-single', 'subject', 'Music from the time of Shakespeare' @@ -188,13 +195,13 @@ # Option child elements it 'allows adding of options' do di = Blather::Stanza::X::Field.new nil di.options.size.must_equal 0 - di.add_options [{:label => 'Person', :value => 'person'}] + di.options += [{:label => 'Person', :value => 'person'}] di.options.size.must_equal 1 - di.add_options [Blather::Stanza::X::Field::Option.new(*%w[person1 Person1])] + di.options += [Blather::Stanza::X::Field::Option.new(*%w[person1 Person1])] di.options.size.must_equal 2 end it 'raises an error when compared against a non X::Field' do a = Blather::Stanza::X::Field.new('hidden', 'secret_message') @@ -223,6 +230,6 @@ n.label = 'Book 1' n.label.must_equal 'Book 1' n.label = 'Book 2' n.label.must_equal 'Book 2' end -end \ No newline at end of file +end