Skip to content

Instantly share code, notes, and snippets.

@tivtag
Created November 3, 2010 18:48
Show Gist options
  • Save tivtag/661502 to your computer and use it in GitHub Desktop.
Save tivtag/661502 to your computer and use it in GitHub Desktop.
Just some odd (incomplete) specification file that verifies a module that reads in locations (in a text adventure) described in a DSL. Also includes the location data files.
location :street do
location :park do
location :bank do
end
end
location :house do
location :door do
end
end
end
require_relative '../lib/location_builder.rb'
include LocationBuilder
describe LocationBuilder do
describe 'when parsing a single simple Location' do
before do
@locations = parse('specs/data/simple_location.rb')
@location = @locations.first
end
it 'returns a single Location' do
@locations.length.should == 1
end
it 'returns a Location that has the specified name' do
@location.name.should == :town
end
it 'returns a Location that has the specified long name' do
@location.long_name.should == 'Viva La Vegas'
end
it 'returns a Location that has the specified description' do
@location.description.should == 'A great town.'
end
it 'returns a Location with no actions' do
@location.has_action(:any).should == false
end
it 'returns a Location with no parent Location' do
@location.parent_location.should == nil
end
it 'still returns only a single Location' do
@locations.length.should == 1
end
end
describe 'when parsing hierarchical Locations' do
before do
@locations = parse('specs/data/hierarchical_locations.rb')
end
it 'returns the correct number of Locations' do
@locations.length.should == 5
end
it 'returns the described Locations' do
names = @locations.map {|location| location.name}
names.should include(:street, :park, :bank, :house, :door)
end
end
end
location :town do
name 'Viva La Vegas'
desc 'A great town.'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment