Created
November 3, 2010 18:48
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
location :street do | |
location :park do | |
location :bank do | |
end | |
end | |
location :house do | |
location :door do | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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