Changeset 275
- Timestamp:
- 06/18/07 09:22:18 (17 months ago)
- Location:
- trunk
- Files:
-
- 1 added
- 5 modified
- 1 moved
-
. (modified) (1 prop)
-
acceptance/epic4.rb (modified) (8 diffs)
-
docs/smoke_and_mirrors.rb (modified) (1 diff)
-
lib/fm/gameobject.rb (modified) (4 diffs)
-
spec/event_spec.rb (modified) (1 diff)
-
spec/gameobject_spec.rb (moved) (moved from trunk/spec/gameobject.tests.rb) (2 diffs)
-
spec/mixins_spec.rb (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:ignore
-
old new 1 1 test.log 2 2 .glimpse* 3 pkg 4 coverage 5 artifacts
-
- Property svn:ignore
-
trunk/acceptance/epic4.rb
r270 r275 26 26 27 27 %w{lib redist}.each do |dir| 28 $LOAD_PATH.unshift( File ::join($basedir, dir) )28 $LOAD_PATH.unshift( File.join($basedir, dir) ) 29 29 end 30 30 } … … 40 40 def invoke( instigator, origin=nil ) 41 41 origin ||= instigator 42 return FaerieMUD::AuditoryEvent ::new(42 return FaerieMUD::AuditoryEvent.new( 43 43 :instigator => instigator, 44 44 :origin => origin, … … 53 53 def invoke( instigator, origin=nil ) 54 54 origin ||= instigator 55 return FaerieMUD::AuditoryEvent ::new(55 return FaerieMUD::AuditoryEvent.new( 56 56 :instigator => instigator, 57 57 :origin => origin, … … 76 76 @tickCount = 0 77 77 @verbs = { 78 :tick => TickVerb ::instance,79 :chime => ChimeVerb ::instance,78 :tick => TickVerb.instance, 79 :chime => ChimeVerb.instance, 80 80 } 81 81 @count = 120 … … 89 89 ### Start a new thread, start ticking in it and return the thread. 90 90 def start 91 @thread = Thread ::new do91 @thread = Thread.new do 92 92 Thread.current.abort_on_exception = true 93 93 @count.times do … … 125 125 126 126 def invoke( speaker, language, words ) 127 return FaerieMUD::SpeechEvent ::new(127 return FaerieMUD::SpeechEvent.new( 128 128 :instigator => speaker, 129 129 :origin => speaker, … … 143 143 @onDuty = true 144 144 @chimeCount = 0 145 @sayVerb = SayVerb ::instance145 @sayVerb = SayVerb.instance 146 146 147 147 super … … 223 223 if $0 == __FILE__ 224 224 if $DEBUG 225 FaerieMUD::Logger ::global.outputters <<226 FaerieMUD::Logger::Outputter ::create( 'file', $stderr, "STDERR" )227 FaerieMUD::Logger ::global.level = :debug225 FaerieMUD::Logger.global.outputters << 226 FaerieMUD::Logger::Outputter.create( 'file', $stderr, "STDERR" ) 227 FaerieMUD::Logger.global.level = :debug 228 228 end 229 229 230 230 # Set up the scene 231 topArea = FaerieMUD::Area ::new232 punchbag = QuasiOrc ::new233 clock = Clock ::new234 observer = Observer ::new231 topArea = FaerieMUD::Area.new 232 punchbag = QuasiOrc.new 233 clock = Clock.new 234 observer = Observer.new 235 235 236 236 # Put the clock and punchbag into the void -
trunk/docs/smoke_and_mirrors.rb
r270 r275 157 157 Readline.readline 158 158 print " Password: " 159 160 159 161 160 formatter = Text::Format.new \ -
trunk/lib/fm/gameobject.rb
r270 r275 60 60 # The authors hash for this class 61 61 @authors = Hash::new( 0 ) 62 @contributors = [] 62 63 class << self 63 64 attr_reader :authors … … 77 78 unless self.instance_variables.include?( "@authors" ) 78 79 self.instance_variable_set( :@authors, Hash::new(0) ) 80 self.instance_variable_set( :@contributors, [] ) 79 81 class << self 80 82 attr_reader :authors … … 85 87 86 88 ### Add one or more authors to the contributors for the current class. 87 def self::contributors( * contributors)89 def self::contributors( *userids) 88 90 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 ) 90 94 self.authors.replace( chart ) 91 95 end … … 168 172 169 173 # This must come after the declaration of the contributors method above. 170 contributors :ged, :stillflame 174 contributors :ged, :stillflame, :phaedrus 171 175 172 176 ### Initialize a new FaerieMUD::GameObject. Arguments in the -
trunk/spec/event_spec.rb
r271 r275 48 48 # | 49 49 # LunarEvent 50 # | ____ Remarkable (mixin)51 # |/52 # |\____ AstrologicallySignificant (mixin)53 50 # | 54 51 # LunarEclipseEvent -
trunk/spec/gameobject_spec.rb
r270 r275 1 1 #!/usr/bin/ruby -w 2 2 # 3 # Unit testfor the FaerieMUD::GameObject class3 # Specification for the FaerieMUD::GameObject class 4 4 # $Id$ 5 5 # 6 # Copyright (c) 2003-200 5The FaerieMUD Consortium.6 # Copyright (c) 2003-2007 The FaerieMUD Consortium. 7 7 # 8 8 … … 12 12 $LOAD_PATH.unshift "#{basedir}/lib" unless 13 13 $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" ) 18 16 end 19 17 18 require 'spec/runner' 20 19 require 'fm/gameobject' 21 20 22 ### Test case for the FaerieMUD::GameObject class and associated classes/modules.23 class GameObjectTestCase < FaerieMUD::TestCase24 21 25 TestingAuthorNames = %w{ged scotus stillflame rhil reltuk bhaij eeeeee} 22 describe 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 33 end 34 35 describe 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 49 end 26 50 27 51 28 ################################################################# 29 ### E X A M P L E S 30 ################################################################# 52 describe FaerieMUD::GameObject, " with two contributors" do 31 53 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 36 60 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 72 end 43 73 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 74 describe "An instance of a FaerieMUD::GameObject" do 75 before( :all ) do 76 @class = Class.new( FaerieMUD::GameObject ) do 77 contributors :mcfly 78 end 51 79 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 95 end 52 96 53 97 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 } 98 describe FaerieMUD::GameObject do 99 before( :all ) do 100 @class = Class.new( FaerieMUD::GameObject ) do 101 SVNRev = 'Rev: 270 ' 102 end 69 103 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 86 108 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 109 end 182 110 183 111 184 112 185 186 end187
