Changeset 275

Show
Ignore:
Timestamp:
06/18/07 09:22:18 (17 months ago)
Author:
ged
Message:

Converted a few more specs

Location:
trunk
Files:
1 added
5 modified
1 moved

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

        old new  
        11test.log 
        22.glimpse* 
         3pkg 
         4coverage 
         5artifacts 
  • trunk/acceptance/epic4.rb

    r270 r275  
    2626 
    2727    %w{lib redist}.each do |dir| 
    28         $LOAD_PATH.unshift( File::join($basedir, dir) ) 
     28        $LOAD_PATH.unshift( File.join($basedir, dir) ) 
    2929    end 
    3030} 
     
    4040    def invoke( instigator, origin=nil ) 
    4141        origin ||= instigator 
    42         return FaerieMUD::AuditoryEvent::new( 
     42        return FaerieMUD::AuditoryEvent.new( 
    4343            :instigator => instigator, 
    4444            :origin => origin, 
     
    5353    def invoke( instigator, origin=nil ) 
    5454        origin ||= instigator 
    55         return FaerieMUD::AuditoryEvent::new( 
     55        return FaerieMUD::AuditoryEvent.new( 
    5656            :instigator => instigator, 
    5757            :origin => origin, 
     
    7676        @tickCount = 0 
    7777        @verbs = { 
    78             :tick => TickVerb::instance, 
    79             :chime => ChimeVerb::instance, 
     78            :tick => TickVerb.instance, 
     79            :chime => ChimeVerb.instance, 
    8080        } 
    8181        @count = 120 
     
    8989    ### Start a new thread, start ticking in it and return the thread.   
    9090    def start 
    91         @thread = Thread::new do 
     91        @thread = Thread.new do 
    9292            Thread.current.abort_on_exception = true 
    9393            @count.times do 
     
    125125 
    126126    def invoke( speaker, language, words ) 
    127         return FaerieMUD::SpeechEvent::new( 
     127        return FaerieMUD::SpeechEvent.new( 
    128128            :instigator => speaker, 
    129129            :origin => speaker, 
     
    143143        @onDuty = true 
    144144        @chimeCount = 0 
    145         @sayVerb = SayVerb::instance 
     145        @sayVerb = SayVerb.instance 
    146146 
    147147        super 
     
    223223if $0 == __FILE__ 
    224224    if $DEBUG 
    225         FaerieMUD::Logger::global.outputters << 
    226             FaerieMUD::Logger::Outputter::create( 'file', $stderr, "STDERR" ) 
    227         FaerieMUD::Logger::global.level = :debug 
     225        FaerieMUD::Logger.global.outputters << 
     226            FaerieMUD::Logger::Outputter.create( 'file', $stderr, "STDERR" ) 
     227        FaerieMUD::Logger.global.level = :debug 
    228228    end 
    229229 
    230230    # Set up the scene  
    231     topArea = FaerieMUD::Area::new 
    232     punchbag = QuasiOrc::new 
    233     clock = Clock::new 
    234     observer = Observer::new 
     231    topArea = FaerieMUD::Area.new 
     232    punchbag = QuasiOrc.new 
     233    clock = Clock.new 
     234    observer = Observer.new 
    235235 
    236236    # Put the clock and punchbag into the void 
  • trunk/docs/smoke_and_mirrors.rb

    r270 r275  
    157157    Readline.readline 
    158158    print "  Password: " 
    159      
    160159 
    161160    formatter = Text::Format.new \ 
  • trunk/lib/fm/gameobject.rb

    r270 r275  
    6060    # The authors hash for this class 
    6161    @authors = Hash::new( 0 ) 
     62    @contributors = [] 
    6263    class << self 
    6364        attr_reader :authors 
     
    7778        unless self.instance_variables.include?( "@authors" ) 
    7879            self.instance_variable_set( :@authors, Hash::new(0) ) 
     80            self.instance_variable_set( :@contributors, [] ) 
    7981            class << self 
    8082                attr_reader :authors 
     
    8587 
    8688    ### Add one or more authors to the contributors for the current class. 
    87     def self::contributors( *contributors ) 
     89    def self::contributors( *userids) 
    8890        self.add_authors_data 
    89         chart = self.distribute_points( *contributors ) 
     91        return @contributors if userids.empty? 
     92        @contributors.replace( userids ) 
     93        chart = self.distribute_points( *userids ) 
    9094        self.authors.replace( chart ) 
    9195    end 
     
    168172 
    169173    # This must come after the declaration of the contributors method above. 
    170     contributors :ged, :stillflame 
     174    contributors :ged, :stillflame, :phaedrus 
    171175 
    172176    ### Initialize a new FaerieMUD::GameObject. Arguments in the  
  • trunk/spec/event_spec.rb

    r271 r275  
    4848#                   | 
    4949#              LunarEvent 
    50 #                   | ____ Remarkable (mixin) 
    51 #                   |/ 
    52 #                   |\____ AstrologicallySignificant (mixin) 
    5350#                   | 
    5451#           LunarEclipseEvent 
  • trunk/spec/gameobject_spec.rb

    r270 r275  
    11#!/usr/bin/ruby -w 
    22# 
    3 # Unit test for the FaerieMUD::GameObject class 
     3# Specification for the FaerieMUD::GameObject class 
    44# $Id$ 
    55# 
    6 # Copyright (c) 2003-2005 The FaerieMUD Consortium. 
     6# Copyright (c) 2003-2007 The FaerieMUD Consortium. 
    77#  
    88 
     
    1212    $LOAD_PATH.unshift "#{basedir}/lib" unless 
    1313        $LOAD_PATH.include?( "#{basedir}/lib" ) 
    14     $LOAD_PATH.unshift "#{basedir}/tests/lib" unless 
    15         $LOAD_PATH.include?( "#{basedir}/tests/lib" ) 
    16  
    17     require 'fmtestcase' 
     14    $LOAD_PATH.unshift "#{basedir}/spec/lib" unless 
     15        $LOAD_PATH.include?( "#{basedir}/spec/lib" ) 
    1816end 
    1917 
     18require 'spec/runner' 
    2019require 'fm/gameobject' 
    2120 
    22 ### Test case for the FaerieMUD::GameObject class and associated classes/modules. 
    23 class GameObjectTestCase < FaerieMUD::TestCase 
    2421 
    25     TestingAuthorNames = %w{ged scotus stillflame rhil reltuk bhaij eeeeee} 
     22describe FaerieMUD::GameObject, " with no contributors" do 
     23 
     24    before( :all ) do 
     25        @class = Class.new( FaerieMUD::GameObject ) 
     26    end 
     27     
     28    it "doesn't give contributor points to anyone if no contributors are list" do 
     29        @class.authors.should be_an_instance_of( Hash ) 
     30        @class.authors.should be_empty() 
     31    end 
     32     
     33end 
     34 
     35describe FaerieMUD::GameObject, " with one contributor" do 
     36 
     37    before( :all ) do 
     38        @class = Class.new( FaerieMUD::GameObject ) do 
     39            contributors :phaedrus 
     40        end 
     41    end 
     42     
     43    it "gives all contributor points for the class to the contributor" do 
     44        @class.authors.should be_an_instance_of( Hash ) 
     45        @class.should have(1).authors 
     46        @class.authors[:phaedrus].should == 100 
     47    end 
     48     
     49end 
    2650 
    2751 
    28     ################################################################# 
    29     ### E X A M P L E S 
    30     ################################################################# 
     52describe FaerieMUD::GameObject, " with two contributors" do 
    3153 
    32     ### Instance test 
    33     def test_00_Instance 
    34         printTestHeader "GameObject: Instantiation" 
    35         rval, derivClass, derivObject = nil, nil, nil 
     54    before( :all ) do 
     55        @class = Class.new( FaerieMUD::GameObject ) do 
     56            contributors :ged, :phaedrus 
     57        end 
     58    end 
     59     
    3660 
    37         # Make sure the class is defined, but not instantiatable. 
    38         assert_instance_of Class, FaerieMUD::GameObject 
    39         assert_nothing_raised { 
    40             rval = FaerieMUD::GameObject::new 
    41         } 
    42         assert_instance_of FaerieMUD::GameObject, rval 
     61    it "gives contributor points to each contributor" do 
     62        @class.should have(2).authors 
     63        @class.authors[:ged].should > 0 
     64        @class.authors[:phaedrus].should > 0 
     65    end 
     66     
     67    it "gives the second contributor listed less contributor points" do 
     68        @class.authors[ @class.contributors.first ].should > 
     69            @class.authors[ @class.contributors.last ] 
     70    end 
     71     
     72end 
    4373 
    44         # Make sure other classes can inherit from it and be instantiated. 
    45         assert_nothing_raised { 
    46             derivClass = Class::new( FaerieMUD::GameObject ) 
    47             derivObject = derivClass::new 
    48         } 
    49  
    50         assert_kind_of FaerieMUD::GameObject, derivObject 
     74describe "An instance of a FaerieMUD::GameObject" do 
     75    before( :all ) do 
     76        @class = Class.new( FaerieMUD::GameObject ) do 
     77            contributors :mcfly 
     78        end 
    5179    end 
     80     
     81    it "knows what an author's contributor points for its class is" do 
     82        @class.new.contribution( :mcfly ).should be_an_instance_of( Fixnum ) 
     83    end 
     84     
     85    it "generates new IDs for clones" do 
     86        obj = @class.new 
     87        obj.id.should_not == obj.clone.id 
     88    end 
     89     
     90    it "creates a new mutex for clones" do 
     91        obj = @class.new 
     92        obj.mutex.should_not == obj.clone.mutex 
     93    end 
     94     
     95end 
    5296 
    5397 
    54     ### Test the authors hash 
    55     def test_10_authors 
    56         printTestHeader "GameObject: Authors" 
    57  
    58         derivClass = Class::new( FaerieMUD::GameObject ) 
    59         rval = nil 
    60          
    61         TestingAuthorNames.each {|name| 
    62             [ FaerieMUD::GameObject, derivClass ].each {|klass| 
    63                 assert_nothing_raised { 
    64                     rval = klass.authors[name] 
    65                 } 
    66                 assert_kind_of Integer, rval 
    67             } 
    68         } 
     98describe FaerieMUD::GameObject do 
     99    before( :all ) do 
     100        @class = Class.new( FaerieMUD::GameObject ) do 
     101            SVNRev = 'Rev: 270 ' 
     102        end 
    69103    end 
    70  
    71  
    72     ### Test the contribution method 
    73     def test_11_contribution 
    74         printTestHeader "GameObject: Contribution" 
    75  
    76         derivClass = Class::new( FaerieMUD::GameObject ) 
    77         derivObj = derivClass::new 
    78         rval = nil 
    79          
    80         TestingAuthorNames.each {|name| 
    81             assert_nothing_raised { 
    82                 rval = derivObj.contribution( name ) 
    83             } 
    84             assert_kind_of Integer, rval 
    85         } 
     104     
     105     
     106    it "can extract a numeric version from its subversion rev number" do 
     107        @class.rev.should == 270 
    86108    end 
    87  
    88  
    89     ### Test the contributors class method 
    90     def test_20_contributors 
    91         printTestHeader "GameObject: Contributors" 
    92         derivClass, derivObject, rval, lastval, lastname = [nil] * 5 
    93  
    94         assert_nothing_raised { 
    95             derivClass = Class::new( FaerieMUD::GameObject ) { 
    96                 contributors :ged, :scotus, :stillflame, 
    97                     :rhil, :reltuk, :bhaij 
    98             } 
    99         } 
    100         assert_nothing_raised { derivObject = derivClass::new } 
    101  
    102         %w{ged stillflame scotus rhil reltuk bhaij eeeeee}.each {|name| 
    103             assert_nothing_raised { 
    104                 rval = derivObject.contribution( name ) 
    105             } 
    106  
    107             debug_msg "Last contributor's contribution (%s/%d); this one's (%s/%d)" % 
    108                 [ lastname, lastval, name, rval ] 
    109  
    110             assert_kind_of Integer, rval 
    111             assert lastval.nil? || lastval >= rval, 
    112                 "Last contributor's contribution (%s/%d) was greater than "\ 
    113                 "this one's (%s/%d)" % 
    114                 [ lastname, lastval, name, rval ] 
    115  
    116             lastname = name 
    117             lastval = rval 
    118         } 
    119     end 
    120  
    121  
    122     ### Test versioning 
    123     def test_30_versioning 
    124         printTestHeader "GameObject: versioning" 
    125         obj = rev = rval = nil 
    126  
    127         derivClass = Class::new( FaerieMUD::GameObject ) { 
    128             self::const_set( :SVNRev, %q{Rev: 101 } ) 
    129         } 
    130  
    131         # Class revision 
    132         assert_nothing_raised { rev = derivClass::rev } 
    133         assert_equal 101, rev 
    134  
    135         # Instance revision 
    136         obj = derivClass::new 
    137         assert_nothing_raised { rval = obj.rev } 
    138         assert_equal rev, rval 
    139     end 
    140  
    141  
    142     ### Test the to_html method 
    143     def test_50_toHtml 
    144         printTestHeader "GameObject: to_html" 
    145  
    146         derivClass = Class::new( FaerieMUD::GameObject ) { 
    147             def initialize 
    148                 @test1 = "foo" 
    149                 @test2 = "<foo atchoo" 
    150                 @test3 = "Other & random >> stuff" 
    151  
    152                 super 
    153             end 
    154         } 
    155         derivObj = derivClass::new 
    156         rval = nil 
    157  
    158         assert_nothing_raised { rval = derivObj.to_html } 
    159         assert_equal rval.count("<"), rval.count(">"), 
    160             "Angle-bracket balance" 
    161         assert_match( /@test1/, rval, "@test1 ivar" ) 
    162         assert_match( /@test2/, rval, "@test2 ivar" ) 
    163         assert_match( /@test3/, rval, "@test3 ivar" ) 
    164     end 
    165  
    166  
    167     ### Cloned objects should get unique ids and mutexen 
    168     def test_clonedObjectsShouldHaveUniqueIds 
    169         printTestHeader "GameObject: cloned objects should have unique ids and mutexes" 
    170  
    171         derivClass = Class::new( FaerieMUD::GameObject ) 
    172         derivObj = derivClass::new 
    173         clonedObj = nil 
    174  
    175         assert_nothing_raised do 
    176             clonedObj = derivObj.clone 
    177         end 
    178  
    179         assert_not_same derivObj.id, clonedObj.id 
    180         assert_not_same derivObj.mutex, clonedObj.mutex 
    181     end 
     109end 
    182110 
    183111 
    184112 
    185  
    186 end 
    187