Changeset 259


Ignore:
Timestamp:
Sep 14, 2009, 1:21:16 PM (11 years ago)
Author:
KOBAYASHI, Shinji
Message:

support/identification package moving from test/unit to rspec

Location:
ruby/branches/0.5
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • ruby/branches/0.5/lib/open_ehr/assumed_library_types.rb

    r256 r259  
    9595
    9696      def self.valid_year?(year)
    97         year >= 0
     97        return !year.nil? && year >= 0
    9898      end
    9999
    100100      def self.valid_day?(y, m, d)
    101         Date.valid_date?(y,m,d) and valid_year? y
     101        unless y.nil? || m.nil? || d.nil?
     102          return Date.valid_date?(y,m,d)
     103        end
     104        if (y.nil?) || (m.nil? && !d.nil?)
     105          return false
     106        end
     107        return self.valid_year?(y) && self.valid_month?(m)
    102108      end
    103109
     
    126132
    127133      def year=(year)
    128         unless !year.nil? && ISO8601Date.valid_year?(year)
     134        unless ISO8601Date.valid_year?(year)
    129135          raise ArgumentError, "Year is not valid"
    130136        end
     
    138144
    139145      def day=(day)
     146       
    140147        raise ArgumentError, "Day is not valid" unless day.nil? or ISO8601Date.valid_day?(@year, @month, day)
    141148        @day = day
     
    548555      end
    549556    end
     557
    550558    class ISO8601_DURATION < TimeDefinitions
    551559      include ISO8601_DURATION_MODULE
  • ruby/branches/0.5/lib/open_ehr/rm/support/identification.rb

    r216 r259  
    66    module Support
    77      module Identification
    8         class ObjectId
     8        class ObjectID
    99          attr_reader :value
    1010
    11           def initialize(value)
    12             self.value=value
     11          def initialize(args = {})
     12            self.value=args[:value]
    1313          end
    1414
     
    1717            @value = value           
    1818          end
     19
    1920          def ==(object_id)
    2021            @value == object_id.value
     
    3233
    3334          def namespace=(namespace)
    34             raise ArgumentError if namespace.nil? or namespace.empty? or !(/([a-z]|[A-Z]).*/ =~ namespace) # error original is =~ #([a-z][A-Z])([a-z]|[A-Z]|\s|[0-9]|[_-\:\/\&\+\?])*/
     35            raise ArgumentError if namespace.nil? or namespace.empty? or !(/([a-z]|[A-Z]).*/ =~ namespace) # error original is =~ #([a-z][A-Z])([a-z]|[A-Z]|\s|[v0-9]|[_-\:\/\&\+\?])*/
    3536            @namespace = namespace
    3637          end
     
    4748        end
    4849
    49         class ArchetypeId < ObjectId
     50        class ArchetypeID < ObjectID
    5051          attr_reader :domain_concept, :rm_name, :rm_entity, :rm_originator, :specialisation, :version_id
    5152
     
    9091        end
    9192
    92         class TerminologyId < ObjectId
     93        class TerminologyID < ObjectID
    9394          attr_reader :name, :version_id
    9495
    95           def initialize(value)
    96             super(value)
     96          def initialize(args = {})
     97            super(args)
    9798          end
    9899
     
    129130        end # of Terminology_ID
    130131
    131         class GenericId < ObjectId
     132        class GenericID < ObjectID
    132133          attr_reader :scheme
    133134
     
    143144        end # of Generic_ID
    144145
    145         class TemplateId < ObjectId
    146 
    147         end
    148 
    149         class UidBasedId < ObjectId
     146        class TemplateID < ObjectID
     147
     148        end
     149
     150        class UIDBasedID < ObjectID
    150151          def initialize(value)
    151152            super(value)
     
    173174        end
    174175
    175         class ObjectVersionId < UidBasedId
     176        class ObjectVersionID < UIDBasedID
    176177          attr_reader :object_id, :creating_system_id, :version_tree_id
    177178
     
    183184            super(value)
    184185            if /^(\w+)::(\w+)::((\d|\.)+)$/ =~ value
    185               self.object_id = Uid.new($1)
    186               self.creating_system_id = Uid.new($2)
    187               self.version_tree_id = VersionTreeId.new($3)
     186              self.object_id = UID.new($1)
     187              self.creating_system_id = UID.new($2)
     188              self.version_tree_id = VersionTreeID.new($3)
    188189            else
    189190              raise ArgumentError, 'invalid format'
     
    249250        end
    250251
    251         class HierObjectId < UidBasedId
    252 
    253         end
    254 
    255         class VersionTreeId
     252        class HierObjectID < UIDBasedID
     253
     254        end
     255
     256        class VersionTreeID
    256257          attr_reader :value, :trunk_version, :branch_number, :branch_version
    257258
     
    302303        end
    303304
    304         class Uid
     305        class UID
    305306          attr_reader :value
    306307
     
    315316        end
    316317
    317         class Uuid < Uid
    318 
    319         end
    320 
    321         class InternetId <Uid
     318        class UUID < UID
     319
     320        end
     321
     322        class InternetID <UID
    322323         
    323324        end
    324325
    325         class IsoOid <Uid
     326        class IsoOID <UID
    326327
    327328        end       
  • ruby/branches/0.5/spec/lib/open_ehr/assumed_library_types/interval_spec.rb

    r256 r259  
    1 <<<<<<< .mine
    21require File.dirname(__FILE__) + '/../../../spec_helper'
    32include OpenEHR::AssumedLibraryTypes
     
    139138  end
    140139end
    141 =======
    142 require File.dirname(__FILE__) + '/../../../spec_helper'
    143 include OpenEHR::AssumedLibraryTypes
    144140
    145 describe Interval do
    146   before(:each) do
    147     @interval = Interval.new(:upper => 10,
    148                              :lower => 1)
    149   end
    150 
    151   it 'should be an instance of Interval' do
    152     @interval.should be_an_instance_of Interval
    153   end
    154 
    155   it 's upper should be greater than lower' do
    156     @interval.upper.should be > @interval.lower
    157   end
    158 
    159   it 's upper should be equal 10' do
    160     @interval.upper.should == 10
    161   end
    162 
    163   it 's lower should be equal 1' do
    164     @interval.lower.should == 1
    165   end
    166 
    167   it 'should raise ArgumentError with smaller upper' do
    168     lambda {@interval.upper = -1}.should raise_error ArgumentError
    169   end
    170 
    171   it 'should raise ArgumentError with greater lower' do
    172     lambda {@interval.lower = 11}.should raise_error ArgumentError
    173   end
    174 
    175   it 'should have 5' do
    176     @interval.has?(5).should be_true
    177   end
    178 
    179   it 'should not have 11' do
    180     @interval.has?(11).should_not be_true
    181   end
    182 
    183   it 'should not have -1' do
    184     @interval.has?(-1).should_not be_true
    185   end
    186 
    187   it 'should not have 10' do
    188     @interval.has?(10).should_not be_true
    189   end
    190 
    191   it 'should have not have 1' do
    192     @interval.has?(1).should_not be_true
    193   end
    194 
    195   describe Interval, 'when lower included' do
    196     before do
    197       @interval.lower_included = true
    198     end
    199 
    200     it 'should be lower_included' do
    201       @interval.should be_lower_included
    202     end
    203 
    204     it 'should have 1 when lower included' do
    205       @interval.has?(1).should be_true
    206     end
    207 
    208     after do
    209       @interval.lower_included = false
    210     end
    211   end
    212 
    213   describe Interval, 'when upper included' do
    214     before do
    215       @interval.upper_included = true
    216     end
    217 
    218     it 'should be upper uncluded' do
    219       @interval.should be_upper_included
    220     end
    221 
    222     it 'should have 10 when upper included' do
    223       @interval.has?(10).should be_true
    224     end
    225 
    226     after do
    227       @interval.upper_included = false
    228     end
    229   end
    230 
    231   describe Interval, 'when upper unbounded' do
    232     before do
    233       @interval.upper = nil
    234     end
    235 
    236     it 'should be upper unbounded' do
    237       @interval.should be_upper_unbounded
    238     end
    239 
    240     it 'should have 11' do
    241       @interval.has?(11).should be_true
    242     end
    243 
    244     it 'should raise ArgumentError, when upper_included is assigned' do
    245       lambda{
    246         @interval.upper_included = true
    247       }.should raise_error ArgumentError
    248     end
    249 
    250     after do
    251       @interval.upper = 10
    252     end
    253   end
    254 
    255   describe Interval, 'when lower unbounded' do
    256     before do
    257       @interval.lower = nil
    258     end
    259 
    260     it 'should be lower unbounded' do
    261       @interval.should be_lower_unbounded
    262     end
    263 
    264     it 'should  have -10' do
    265       @interval.has?(-10).should be_true
    266     end
    267 
    268     it 'should raise ArgumentError, when lower_included is assigned' do
    269       lambda{
    270         @interval.lower_included = true
    271       }.should raise_error ArgumentError
    272     end
    273   end
    274 
    275   it 'should raise ArgumentError both upper and lower is nil' do
    276     lambda {
    277       Interval.new
    278     }.should raise_error ArgumentError
    279   end
    280 end
    281 >>>>>>> .r255
  • ruby/branches/0.5/spec/lib/open_ehr/assumed_library_types/iso_8601_date_spec.rb

    r256 r259  
    2525  it 'should be 2009-09-10 as_string' do
    2626    @iso8601date.as_string.should == '2009-09-10'
     27  end
     28
     29  it 'should be extended ' do
     30    @iso8601date.is_extended?.should be_true
    2731  end
    2832
     
    6569  end
    6670
    67   describe 'January behavior' do
    68     before do
    69       @iso8601date.month = 1
    70     end
     71  [1,3,5,7,8,10,12].each do |m|
     72    describe '#{m}th month behavior' do
     73      before do
     74        @iso8601date.month = m
     75      end
     76     
     77      it 'should have 31 days' do
     78        lambda{
     79          @iso8601date.day = 31
     80        }.should_not raise_error ArgumentError
     81      end
    7182
    72     it 'January should have 31 days' do
    73       lambda{@iso8601date.day = 31}.should_not raise_error ArgumentError
    74     end
    75 
    76     it 'January should not have 32 days' do
    77       lambda{@iso8601date.month = 32}.should raise_error ArgumentError
     83      it 'should not have 32 days' do
     84        lambda{
     85          @iso8601date.day = 32
     86        }.should raise_error ArgumentError
     87      end
    7888    end
    7989  end
     
    127137  end
    128138
    129   describe 'March behavior' do
    130     before do
    131       @iso8601date.month = 3
    132     end
     139  [4,6,9,11].each do |month|
     140    describe "#{month}th month behavior" do
     141      before do
     142        @iso8601date.month = month
     143      end
    133144
    134     it '31 day should not raise ArgumentError' do
    135       lambda{@iso8601date.day = 31}.should_not raise_error ArgumentError
    136     end
     145      it '30 day should not raise ArgumentError' do
     146        lambda{
     147          @iso8601date.day = 30
     148        }.should_not raise_error ArgumentError
     149      end
    137150
    138     it '32 day should raise ArgumentError' do
    139       lambda{@iso8601date.day = 32}.should raise_error ArgumentError
     151      it '31 day should raise ArgumentError' do
     152        lambda{
     153          @iso8601date.day = 31
     154        }.should raise_error ArgumentError
     155      end
    140156    end
    141157  end
    142158
    143   describe 'April behavior' do
    144     before do
    145       @iso8601date.month = 4
     159  describe 'partial date data' do
     160    describe 'day unknown' do
     161      before do
     162        @iso8601date.day = nil
     163      end
     164     
     165      it 'day should be unknown' do
     166        @iso8601date.should be_day_unknown
     167      end
     168     
     169      it 'should be 2009-09 as string' do
     170        @iso8601date.as_string.should == '2009-09'
     171      end
     172     
     173      it 'should be partial' do
     174        @iso8601date.is_partial?.should be_true
     175      end
     176     
     177      after do
     178        @iso8601date.day = 10
     179      end
    146180    end
    147 
    148     it '30 day should not raise ArgumentError' do
    149       lambda{@iso8601date.day = 30}.should_not raise_error ArgumentError
    150     end
    151 
    152     it '31 day should raise ArgumentError' do
    153       lambda{@iso8601date.day = 31}.should raise_error ArgumentError
     181   
     182    describe 'month unknown' do
     183      before do
     184        @iso8601date.day = nil
     185        @iso8601date.month = nil
     186      end
     187     
     188      it 'should raise ArgumentError with nil month and not nil day' do
     189        lambda {
     190          @iso8601date.day = 11
     191        }.should raise_error ArgumentError
     192      end
    154193    end
    155194  end
     195
    156196end
  • ruby/branches/0.5/spec/lib/open_ehr/rm/data_types/basic/dv_state_spec.rb

    r221 r259  
    66describe DvState do
    77  before(:each) do
    8     @terminology_id = TerminologyId.new('openher')
     8    @terminology_id = TerminologyID.new(:value => 'openher')
    99    code_phrase = CodePhrase.new(:code_string => '524',
    1010                                 :terminology_id => @terminology_id)
  • ruby/branches/0.5/spec/lib/open_ehr/rm/data_types/quantity/dv_ordinal_spec.rb

    r248 r259  
    66describe DvOrdinal do
    77  before(:each) do
    8     terminology_id = stub(TerminologyId, :value => 'urine:prot')
     8    terminology_id = stub(TerminologyID, :value => 'urine:prot')
    99    code_phrase = stub(CodePhrase, :terminology_id => terminology_id)
    1010    symbol = stub(DvCodedText, :code_string => '+',
     
    3535
    3636  it 'should be strictry comperable to other DvOrdinal' do
    37     terminology_id = stub(TerminologyId, :value => 'urine:prot')
     37    terminology_id = stub(TerminologyID, :value => 'urine:prot')
    3838    code_phrase = stub(CodePhrase, :terminology_id => terminology_id)
    3939    symbol = stub(DvCodedText, :defining_code => code_phrase)
  • ruby/branches/0.5/spec/lib/open_ehr/rm/data_types/text/code_phrase_spec.rb

    r222 r259  
    55describe CodePhrase do
    66  before(:each) do
    7     terminology_id = TerminologyId.new('openehr')
     7    terminology_id = TerminologyID.new(:value => 'openehr')
    88    @code_phrase = CodePhrase.new(:code_string => '535',
    99                                  :terminology_id => terminology_id)
  • ruby/branches/0.5/spec/lib/open_ehr/rm/data_types/text/dv_text_spec.rb

    r225 r259  
    55describe DvText do
    66  before(:each) do
    7     terminology_id = TerminologyId.new('openehr')
     7    terminology_id = TerminologyID.new(:value => 'openehr')
    88    language = CodePhrase.new(:terminology_id => terminology_id,
    99                              :code_string => 'ja')
  • ruby/branches/0.5/spec/spec.opts

    r255 r259  
    11--colour
    2 --format specdoc
     2--format progress
    33--loadby mtime
    44--reverse
Note: See TracChangeset for help on using the changeset viewer.