spec/woyo/world/location_spec.rb in woyo-world-0.0.6 vs spec/woyo/world/location_spec.rb in woyo-world-0.0.7

- old
+ new

@@ -1,80 +1,96 @@ +require 'spec_helper' require 'woyo/world/world' require 'woyo/world/location' +require 'woyo/world/item' require 'woyo/world/way' describe Woyo::Location do - it 'has attributes' do - expected_attrs = [:name,:description] - Woyo::Location.attributes.sort.should eq expected_attrs.sort - end + let(:location) { Woyo::Location.new :home } - it 'name attribute defaults to id' do - wo = Woyo::Location.new(:home) - wo.name.should eq 'Home' - end - it 'accepts world for parameter context:' do wo = nil expect { wo = Woyo::Location.new(:my_id, context: Woyo::World.new) }.to_not raise_error - wo.context.should be_instance_of Woyo::World + expect(wo.context).to be_instance_of Woyo::World end + it '#here' do + home = Woyo::Location.new :home + expect(home.here).to be home + end + + it '#world' do + world = Woyo::World.new + home = Woyo::Location.new :home, context: world + expect(home.world).to eq world + end + context 'ways' do it 'are listed (#ways)' do home = Woyo::Location.new :home do way( :up ) { to :roof } way( :down ) { to :cellar } way( :out ) { to :garden } end - home.ways.count.should eq 3 - home.ways.keys.should eq [ :up, :down, :out ] + expect(home.ways.count).to eq 3 + expect(home.ways.keys).to eq [ :up, :down, :out ] end it 'are from here' do home = Woyo::Location.new :home do way :door do to :away end end door = home.ways[:door] - door.from.should eq home + expect(door.from).to eq home end it 'go to locations' do home = Woyo::Location.new :home do way :door do to :away end end door = home.ways[:door] - door.to.should be_instance_of Woyo::Location - door.to.id.should eq :away + expect(door.to).to be_instance_of Woyo::Location + expect(door.to.id).to eq :away end end - it '#here' do - home = Woyo::Location.new :home - home.here.should be home - end + context 'items' do - it '#world' do - world = Woyo::World.new - home = Woyo::Location.new :home, context: world - home.world.should eq world - end - - it '#characters' do - home = Woyo::Location.new :home do - character :peter do + let( :home ) do + home = Woyo::Location.new :home do + item( :thing1 ) { description 'Thing One' } + item( :thing2 ) { description 'Thing two' } end end - home.characters.size.should eq 1 - peter = home.characters[:peter] - peter.should be_instance_of Woyo::Character - peter.location.should be home + + it 'are listed' do + expect(home.items.count).to eq 2 + expect(home.items.keys).to eq [ :thing1, :thing2 ] + end + + it 'are accessible' do + expect(thing = home.items[:thing1]).to be_instance_of Woyo::Item + expect(thing.id).to eq :thing1 + expect(thing.description).to eq 'Thing One' + end + end + + # it '#characters' do + # home = Woyo::Location.new :home do + # character :peter do + # end + # end + # home.characters.size.should eq 1 + # peter = home.characters[:peter] + # peter.should be_instance_of Woyo::Character + # peter.location.should be home + # end end