Sha256: 6aa7bd0c06b2f793631a26773be4b63e2242191cfd390f229bf6c28034ede697

Contents?: true

Size: 876 Bytes

Versions: 3

Compression:

Stored size: 876 Bytes

Contents

require "minitest_helper"

module Hermod
  describe XmlSection do

    DateXml = XmlSection.build(formats: {date: "%Y-%m-%d"}) do |builder|
      builder.date_node :date_of_birth
      builder.date_node :anniversary, optional: true
    end

    describe "Date nodes" do
      subject do
        DateXml.new do |dummy|
          dummy.date_of_birth Date.new(1988, 8, 13)
        end
      end

      it "should format the date with the given date string" do
        expect(value_of_node("DateOfBirth")).must_equal "1988-08-13"
      end

      it "should raise an error if given something that isn't a date" do
        expect { subject.anniversary "yesterday" }.must_raise InvalidInputError
      end

      it "should ignore blank dates if the date is optional" do
        subject.anniversary nil
        expect(nodes("Anniversary")).must_be_empty
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hermod-3.0.0 spec/hermod/xml_section_builder/date_node_spec.rb
hermod-2.7.0 spec/hermod/xml_section_builder/date_node_spec.rb
hermod-2.7.0.pre.rc.1 spec/hermod/xml_section_builder/date_node_spec.rb