spec/woyo/world/location_spec.rb in woyo-world-0.0.8 vs spec/woyo/world/location_spec.rb in woyo-world-0.0.9

- old
+ new

@@ -80,17 +80,68 @@ 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 + context 'actions' do + + it 'execute returns changes for location' do + home = Woyo::Location.new :home do + item :thing do + action :make_changes do + execution do |action| + name 'Changed item' + action.name 'Changed action' + location.name 'Changed location' + end + end + end + end + expect(home.item(:thing).action(:make_changes).execute[:changes]).to eq( { + name: "Changed location", + item: { + thing: { + name: "Changed item", + action: { + make_changes: { + name: "Changed action" + } + } + } + } + }) + end + + it 'execute returns changes for location for this execution only' do + home = Woyo::Location.new :home do + item :thing do + action :make_changes do + attribute count: 0 + execution do |action| + action.count += 1 + name "Changed item #{action.count}" + action.name "Changed action #{action.count}" + location.name "Changed location #{action.count}" + end + end + action :more_changes do + execution do |action| + name "Changed item more" + action.name "Changed action more" + location.name "Changed location more" + end + end + end + end + expect(home.item(:thing).action(:make_changes).execute[:changes]).to eq( { + name: "Changed location 1", item: { thing: { name: "Changed item 1", action: { make_changes: { count: 1, name: "Changed action 1" } } } } + }) + expect(home.item(:thing).action(:make_changes).execute[:changes]).to eq( { + name: "Changed location 2", item: { thing: { name: "Changed item 2", action: { make_changes: { count: 2, name: "Changed action 2" } } } } + }) + expect(home.item(:thing).action(:more_changes).execute[:changes]).to eq( { + name: "Changed location more", item: { thing: { name: "Changed item more", action: { more_changes: { name: "Changed action more" } } } } + }) + end + end end