diff --git a/terminator_spec.rb b/terminator_spec.rb index 749dae3..b04ffa2 100644 --- a/terminator_spec.rb +++ b/terminator_spec.rb @@ -20,4 +20,31 @@ subject.protect_sarah_connor! subject.current_mission.should eq("protect: sarah_connor") end + + describe "#protects?" do + it "should return true when protecting Sarah Connor" do + subject.protect_sarah_connor! + subject.protects?(:sarah_connor).should be_true + end + it "should return false when destroying Sarah Connor" do + subject.destroy_sarah_connor! + subject.protects?(:sarah_connor).should be_false + end + it "should protect Sarah and John Connor at the same time" do + subject.protect_sarah_connor! + subject.protect_john_connor! + subject.protects?(:sarah_connor).should be_true + end + end + + describe "#good?" do + it "should return true if the terminator is good" do + subject.protect_sarah_connor! + subject.good?.should be_true + end + it "should return false if the terminator is bad" do + subject.destroy_john_connor! + subject.good?.should be_false + end + end end diff --git a/terminatorable.rb b/terminatorable.rb index 378afd6..0d05284 100644 --- a/terminatorable.rb +++ b/terminatorable.rb @@ -5,7 +5,10 @@ def likes_to_protect(people=[]) ["destroy", "protect"].each do |mission_type| people.each do |person| define_method "#{mission_type}_#{person}!" do + @protected_person ||= [] @current_mission = "#{mission_type}: #{person}" + @protected_person << person if mission_type == "protect" + @mission_type = mission_type end end end @@ -15,5 +18,11 @@ def likes_to_protect(people=[]) def self.included(klass) attr_reader :current_mission klass.extend Terminatorable::ClassMethods + def protects?(person) + @protected_person.include? person + end + def good? + @mission_type == "protect" + end end end